Login Priority with jQuery Mobile and Rails

I try to log in, but I get 500 errors due to a missing template. Any ideas? Why is he trying to display devise/sessions/create ?

Rails 3.1


I use mobylette stones: https://github.com/tscolari/mobylette I developed with the settings:

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)

+4
source share
2 answers

I had to make the following changes to make this work:

configurations / Initializers / devise.rb

config.http_authenticatable_on_xhr = false If you make it false, otherwise jQuery mobile will send XHR requests to log in and you will get error 401.

config.navigational_formats = [:"*/*", "*/*", :html, :mobile]

Otherwise, it does not recognize the format. You think this will work with redirection, but in fact this does not happen. You need to do one more thing.

This hacked me, so I added: config / Initializers / devise_hack.rb

ActionController::Responder.class_eval do alias :to_mobile :to_html end

Now it works.

One more thing; in my .rb application I have this for mobylette to configure my mobile stuff:

respond_to_mobile_requests :skip_xhr_requests => false, :fall_back => :html

Between Responder.class_eval and :fall_back => :html you might think that this is not necessary. Most of the written configuration seems to be the same and duplicated. However, without all these settings, it simply does not work.

+8
source

I also had this problem, I solved it by creating a file in applications> views> devize> session called create.mobile.erb I have the following code:

 <section id="login_redirect_page" data-role="page"> <script type="text/javascript"> window.location = "<%= root_path %>" </script> </section> 

It simply creates a create view in the jquery mobile block and redirects to root_path. I am looking for better ways to do this, although I will post if I come up with something.

+1
source

Source: https://habr.com/ru/post/1381420/


All Articles