sizzle
sizzle

Reputation: 2332

How to use JQuery Mobile in a Ruby on Rails application

What does your routes.rb file look like?

How do you handle mobile vs. web routes? Do you define some sort of namespace?

Should one have a mysite.com/mobile directory? What would be the DRY approach to this?

Upvotes: 1

Views: 1228

Answers (2)

Mark Boulder
Mark Boulder

Reputation: 14277

You don't really need extra views - just put a bunch of <% if mobile? %> into your existing ones.

Inspired by http://scottwb.com/blog/2012/02/23/a-better-way-to-add-mobile-pages-to-a-rails-site/, I added this to my application_controller.rb:

def mobile?
  if session[:mobile_override]
    session[:mobile_override] == "1"
  else
    request.user_agent.downcase =~ /mobile|android|touch|webos|hpwos/
  end
end
helper_method :mobile?

The same article also goes to show why using custom domains/routes for mobile is a bad idea.

Upvotes: 0

Ultimation
Ultimation

Reputation: 1069

I think this can get you on the right track: http://railscasts.com/episodes/199-mobile-devices

Upvotes: 3

Related Questions