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.
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
精彩评论