Rails 3中的form_for Ajax调用 [英] Rails 3 form_for ajax call
本文介绍了Rails 3中的form_for Ajax调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有方法在我的控制器:
I have method in my controller:
def work_here
@company = Company.find(params[:id])
current_user.work_apply(current_user, @company)
redirect_to company_path
end
在我的观点:
<%= render 'companies/work_form' if signed_in? %>
_work_form.html.erb:
_work_form.html.erb:
<%= form_for company, :remote => true, :url => { :controller => "companies", :action => "work_here" } do |f| %>
<%= f.hidden_field :id, :value => company.id %>
<%= f.submit "I working here" %>
&LT;%结束%>
<% end %>
和我有一个work_here.js.erb文件:
And I have a work_here.js.erb file:
$("#work_at_form").html("<%= escape_javascript("render('companies/works')") %>")
不过我的表格没有Ajax请求的工作(在其他页精AJAX叉),我js.erb文件从来没有使用。 谁能给我指教? 谢谢你。
But my form works without ajax request(in other pages ajax forks fine), my js.erb file never use. Can anyone give me advise? Thanks.
推荐答案
该work_here.js.erb无法阅读,因为你永远不调用它。一个重定向就是百达做的。使其当请求JS格式。
The work_here.js.erb can't be read because you never call it. A redirect is allways do. render it when the request is js format.
def work_here
@company = Company.find(params[:id])
current_user.work_apply(current_user, @company)
respond_to do |format|
format.html { redirect_to company_path }
format.js { render }
end
end
这篇关于Rails 3中的form_for Ajax调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文