无法让 ajax form_for 尊重 format.js respond_to 仅响应 format.html。非常感谢任何帮助。
看法
此视图由 AJAX 部分调用,然后用户提交表单。最初的 ajax 调用会混淆这种形式的“remote:true”吗?
<%= 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 %>
路线.rb
resources :nested do
resources :resources
end
控制器
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 存在但为空
应用程序.html
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
应用程序.js
//= require jquery
//= require jquery_ujs