How does "response_with_navigational" work?

I work with Devise and DeviseInvitable to manage authentication in my application, and I'm having trouble adding AJAX support to update InvitationsController #. The controller in DeviseInvitable looks like this:

# invitations_controller.rb # PUT /resource/invitation def update self.resource = resource_class.accept_invitation!(params[resource_name]) if resource.errors.empty? set_flash_message :notice, :updated sign_in(resource_name, resource) respond_with resource, :location => after_accept_path_for(resource) else respond_with_navigational(resource){ render_with_scope :edit } end end 

Does this work well when resource.errors.empty? == true resource.errors.empty? == true and we execute:

 respond_with resource, :location => after_accept_path_for(resource) 

(that is, the /update.js.erb prompts are displayed and my javascript calls are executed). The problem is that when is resource.errors.empty? == false resource.errors.empty? == false , and we execute:

 respond_with_navigational(resource){ render_with_scope :edit } 

the server says:

 Rendered invitations/update.js.erb (1.4ms) 

but my javascript calls are not starting. Can someone explain what respond_with_navigational should do? I worked on the Internet for many hours, and I have not found an explanation for this api anywhere.

Thanks!

+6
source share
1 answer

Ok, I will find out what respond_with_navigational does. It is defined in the base classes of Devise as such:

 def respond_with_navigational(*args, &block) respond_with(*args) do |format| format.any(*navigational_formats, &block) end end 

and navigational_formats also defined in the Development section:

 # Returns real navigational formats which are supported by Rails def navigational_formats @navigational_formats ||= Devise.navigational_formats.select{ |format| Mime::EXTENSION_LOOKUP[format.to_s] } end 

So this is basically a wrapper for respond_with() . To make this work, I had to add the following to my InvitationsController:

 respond_to :html, :js 

and now update.js.erb displayed correctly.

+10
source

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


All Articles