weixin_33690963 2011-01-25 07:57 采纳率: 0%
浏览 27

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

On my view:

<%= render 'companies/work_form' if signed_in? %>

_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" %>

<% end %>

And I have a work_here.js.erb file:

$("#work_at_form").html("<%= escape_javascript("render('companies/works')") %>")

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.

  • 写回答

1条回答 默认 最新

  • weixin_33688840 2011-01-25 08:19
    关注

    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
    
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?