Ruby-on-rails – Ruby On Rails Mobile Application

I am trying to develop a Ruby on Rails application that will detect the client, that is, the mobile device (browser) that connects to the server and renders the appropriate layout.
I try to use The following link but still can’t connect to it. Any suggestions?

http://www.arctickiwi.com/blog/mobile-enable-your-ruby-on-rails-site-for-small-screens

I am Use Opera Mini Emulator to test the application.

The most elegant solution I’ve seen is to do Two things: Identify mobile users based on the user agent in the request, and respond with a custom Rails mime type, allowing mobile users to use custom HTML templates.

In config / initializers / mime_types Define a custom “mobile” Rails MIME type in .rb, which is just HTML:

Mime::Type.register_alias "text/html", :mobile

Add help/filter to respond to mobile users:

def mobile_user_agent?
@mobile_user_agent ||= (request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(Mobile/.+Safari)/] )
end

Then…

 before_filter :handle_mobile

def handle_mobile
request.format = :mobile if mobile_user_agent?
end

Make a custom mobile template:

app/views/users/show.html.erb => app/views/users/show.mobile.erb

Send mobile or general in the controller:

respond_to do |format|
format.html {} # Regular stu ff
format.mobile {} # other stuff
end

I am trying to develop a Ruby on Rails application which will detect the client, That is, a mobile device (browser) that connects to the server and renders the appropriate layout.
I tried to use the following link but still cannot connect to it. Any suggestions?

http://www.arctickiwi.com/blog/mobile-enable-your-ruby-on-rails-site-for-small-screens

I am Use Opera Mini Emulator to test the application.

The most elegant solution I have seen is to do two things: identify user agent-based Mobile users and respond with custom Rails mime types, allowing mobile users to use custom HTML templates.

Define a custom “mobile” Rails in config/initializers/mime_types.rb MIME type, it’s just HTML:

Mime::Type.register_alias "text/html", :mobile

Add help/filter to respond to mobile User:

def mobile_user_agent?
@mobile_user_agent ||= (request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(Mobile /.+Safari)/] )
end

Then…

before_filter :handle_mobile

def handle_mobile
request.format = :mobile if mobile_user_agent?
end

Make a custom mobile template:

app/views/ users/show.html.erb => app/views/users/show.mobile.erb

Send mobile or regular in the controller:

 respond_to do |format|
format.html {} # Regular stuff
format.mobile {} # other stuff
end

Leave a Comment

Your email address will not be published.