I’m trying to get devise to login but I’m getting a 500 error due to missing template. Any idea? Why is it trying to render devise/sessions/create ?
Rails 3.1
I’m using the mobylette gem: https://github.com/tscolari/mobylette
I have devise configured with:
config.navigational_formats = [:"*/*", "*/*", :html, :mobile]
Completed 500 Internal Server Error in 145msActionView::MissingTemplate (Missing template devise/sessions/create, application/create with {:handlers=>[:erb, :builder, :coffee, :haml], :formats=>[:mobile], :locale=>[:en, :en]}. Searched in: * "/Users/Armageddon/Projects/Business/jquerymobiletest/app/views" * "/Users/Armageddon/.rvm/gems/ruby-1.9.2-p180-patched@jquerymobiletest/gems/devise-1.4.9/app/views"): Rendered /Users/Armageddon/.rvm/gems/ruby-1.9.2-p180-patched@jquerymobiletest/gems/actionpack-3.1.0/lib/action_dispatch/middleware/templates/rescues/missing_template.erb within rescues/layout (0.5ms)
I had to make the following changes to make this work:
config/initializers/devise.rb
config.http_authenticatable_on_xhr = falseHad to make that false otherwise jQuery mobile sends XHR requests to login and you get a 401 error.
config.navigational_formats = [:"*/*", "*/*", :html, :mobile]This otherwise it wouldn’t recognize the format. You’d think this would handle the redirections but it actually doesn’t. You need to do one more thing.
It’s hacky to me so I added it to:
config/initializers/devise_hack.rb
ActionController::Responder.class_eval doalias :to_mobile :to_html
end
Now it works.
One more thing though; in my application.rb I have this for mobylette to setup my mobile stuff:
respond_to_mobile_requests :skip_xhr_requests => false, :fall_back => :html
Between the
Responder.class_evaland the:fall_back => :htmlyou’d think that these wouldn’t be necessary. A lot of the config’s written seem to be the same thing and or duplicated. However without all of these settings it just doesn’t work.