Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save lachlanhardy/278823 to your computer and use it in GitHub Desktop.

Select an option

Save lachlanhardy/278823 to your computer and use it in GitHub Desktop.
helpers do
def mobile_request?
mobile_user_agent_patterns.any? {|r| request.env['HTTP_USER_AGENT'] =~ r}
end
def mobile_user_agent_patterns
[
/AppleWebKit.*Mobile/,
/Android.*AppleWebKit/
]
end
end
before do
!mobile_request? ? @mobile = ".mobile" : @mobile = ""
end
# homepage
get '/' do
haml :"index#{@mobile}", :layout => :"layout#{@mobile}"
end
# And then I just have an index.haml & a index.mobile.haml as well as a layout.haml and a layout.mobile.haml
# Still needs some tidying up - but it works! And that's good enough for this hour. Bed time!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment