-
Notifications
You must be signed in to change notification settings - Fork 5.5k
How To: Make Devise work with other formats like mobile, iPhone and iPad (Rails specific)
-
Make your app render Apple iOS templates for iOS devices like iPhone, iPad, iPod Touch, etc.
Add the following to
app/controllers/application_controller.rb
:# app/controllers/application_controller.rb class ApplicationController < ActionController::Base before_filter :adjust_format_for_iphone private def adjust_format_for_iphone request.format = :ios if request.env["HTTP_USER_AGENT"] =~ %r{Mobile/.+Safari} end end
-
Set Devise to display views for iOS.
Add every desired format to
config.navigational_formats
inconfig/initializers/devise.rb
.# config/initializers/devise.rb ... config.navigational_formats = [:"*/*", "*/*", :html, :ios] ...
-
Create each view you need for Devise (login form, signup form, etc.).
Name your view something like
new.**ios**.erb
, e.g.app/views/devise/sessions/new.ios.erb
for login form. -
Create an initializer in
config/initializers
(e.g.config/initializers/mobile_formats.rb
) with the following:# config/initializers/mobile_formats.rb ActionController::Responder.class_eval do alias :to_ios :to_html end
-
Add your format to config/initializers/mime_types.rb
# config/initializers/mime_types.rb Mime::Type.register_alias "text/html", :ios
-
Note that if you use OAUTH for Facebook you will need to configure it to use facebook's mobile authentication path. This post explains how.