-
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)
Garrett George edited this page Mar 16, 2021
·
3 revisions
- Make your app render Apple iOS templates for iOS devices like iPhone, iPad, iPod Touch, etc.
In the Rails
app/controllers/application_controller.rb
add this code:
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
-
Set Devise to display views for iOS In the
config/initializers/devise.rb
, look for the 'config.navigational_formats' and add every other formats you haveconfig.navigational_formats = [:"*/*", "*/*", :html, :ios]
-
Create each view you need for Devise (login form, signup form, ...) Name your view like 'new.ios.erb' eg: 'app/views/devise/sessions/new.ios.erb' for login form
-
Create an initializer in the folder config/initializers Add this code into your initializer
ActionController::Responder.class_eval do
alias :to_ios :to_html
end
This code has to correspond to your format (ie: :to_ios, :to_ipad, :to_mobile)
- Add your format to 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.