We have a working app using Devise for authentication (email, password).
To add the mobile interface we're using jQuery mobile — everything works fine, except the login via Devise won't behave.
After hitting “login” Rails processes the request correctly but all we get is a MissingTemplate (devise/sessions/create) error.
Current settings:
config.http_authenticatable_on_hxr = false
config.navigational_formats = [:"*/*", "*/*", :html, :mobile]
We're inspired by Railscast #199 (hence :mobile
): http://railscasts.com/episodes/199-mobile-devices
Try the last step in this guide How To: Make Devise work with other formats like mobile, iphone and ipad (Rails specific).
Remember to use :to_mobile instead of :to_ios, so:
ActionController::Responder.class_eval do
alias :to_mobile :to_html
end
in a new initializer file in config/initializers
Overwriting Devise's SessionsController
works. I took the controller's code from github and added the redirect_to for mobile devices:
app/controllers/sessions_controller.rb
:
class SessionsController < Devise::SessionsController
def create
resource = warden.authenticate!(:scope => resource_name, :recall => "#{controller_path}#new")
set_flash_message(:notice, :signed_in) if is_navigational_format?
sign_in(resource_name, resource)
if mobile_device?
redirect_to wherever_you_want
else
respond_with resource, :location => redirect_location(resource_name, resource)
end
end
end
And in routes.rb
:
devise_for :users, :path => '/', :controllers => { :sessions => "sessions" }
Don't forget to create app/views/sessions/
templates.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With