Form_for [@nested, @resource], remote => true, responding with format.html rails 3.2.6

Cannot get ajax form_for to respect format.js reply_to only format.html answers. Any help is greatly appreciated.

view

This view is called partial AJAX, and then the user submits the form. Can the original ajax call confuse "remote: true" of this form?

<%= form_for([@nested, @nested.resources.new], remote: true) do |i|%> <%= i.hidden_field :inviter_id, value: current_user.id %> <%= i.hidden_field :fb_pic_url, value: f['pic_square'] %> <%= i.hidden_field :name, value: f['name'] %> <%= i.hidden_field :uid, value: f['uid'] %> <%= i.submit "Invite", class:"btn btn-success invite_button" %> <% end %> 

routes.rb

 resources :nested do resources :resources end 

controller

 def create code code code respond_to do |format| format.html { redirect_to @nested, notice: "Successfully Posted Nested" } format.json { render json: @nested, status: :created, location: @nested } format.js { render :nothing => true } end end 

create.js.erb Present but empty

application.html

 <%= javascript_include_tag "application" %> <%= csrf_meta_tags %> 

application.js

 //= require jquery //= require jquery_ujs 
+7
source share
1 answer

Make sure you have a built-in built-in built-in non-intrusive jquery plugin as it is responsible for creating the remote: true code.

also, if you want to display the create.js.erb template, you need to leave the format.js line without a block:

 respond_to do |format| ... format.js end 

Also, do you use other response formats? json and html ? if not, try to avoid placing them.

+2
source

All Articles