为什么我用remote_form_tag:定义的动作不张贴的行动呢?
-
26-09-2019 - |
题
这就是我与remote_form_tag使用的:
<% form_remote_tag(:url => {:controller => '/companies', :action => 'update'},
:update => 'tags') do %>
<%= text_field :company, :tag_list %>
<%= submit_tag 'Save' %>
<% end %>
这是在Company.view,其中公司是一个模型,该模型是acts_as_taggable_on启用。
我的期望是,通过AJAX,一个柱的公司/ 10 /更新由
但是,相反,什么是贴的是:
http://localhost:3000/companies/10
和响应是:
No action responded to 10. Actions: create, destroy, edit, email_this_week, index, new, show, and update
这是在CompaniesController的更新方法:
def update
@company = Company.find(params[:id])
if request.xhr?
# add the given tag to the company
@company.tags << params[:company][:taglist]
@company.save
render :partial => 'tags'
else
if @company.update_attributes(params[:company])
flash[:notice] = "Successfully updated company."
redirect_to @company
else
render :action => 'edit'
end
end
end
帮助...?
DELETE /companies/:company_id/contacts/:id(.:forma
{:controller=>"contacts", :action=>"destroy"}
companies GET /companies(.:format)
{:controller=>"companies", :action=>"index"}
POST /companies(.:format)
{:controller=>"companies", :action=>"create"}
new_company GET /companies/new(.:format)
{:controller=>"companies", :action=>"new"}
edit_company GET /companies/:id/edit(.:format)
{:controller=>"companies", :action=>"edit"}
company GET /companies/:id(.:format)
{:controller=>"companies", :action=>"show"}
PUT /companies/:id(.:format)
{:controller=>"companies", :action=>"update"}
DELETE /companies/:id(.:format)
{:controller=>"companies", :action=>"destroy"}
解决方案
在用ID 10更新等公司的资源时,Rails将使用的RESTful路线:
PUT /companies/10
路由您的请求时,PUT方法被考虑。从你的路由摘自:
PUT /companies/:id(.:format)
{:controller=>"companies", :action=>"update"}
这是为Rails正确的行为。只要实现你的update
的CompaniesController
方法。
如果您需要在Rails的REST风格的路线的详细信息,请查看了这份文件:的http://指南.rubyonrails.org / routing.html
不隶属于 StackOverflow