我有一个创建广告的表格。
控制器:
def edit
@engines = Engine.all
@car = Car.find(params[:id])
end
def update
@car = Car.find(params[:id])
if @car.save
redirect_to root_path
end
end
我的路线:
resources :adverts
创建.html.erb
<%= form_for @car, :url => adverts_path do |f| %>
<div><%= f.label :name %><br />
<%= f.text_field :name %></div>
<%= hidden_field_tag :model_id, params[:model_id] %>
<%= select_tag :engine_id, options_from_collection_for_select(@engines, "id", "name",:selected=>@car.engine_id) %>
<div><%= f.submit "Create car!" %></div>
<% end %>
我可以创建广告,但我不能更新它。
编辑.html.erb
<%= form_for @car, :url => adverts_path do |f| %>
<div><%= f.label :name %><br />
<%= f.text_field :name %></div>
<%= hidden_field_tag :model_id, params[:model_id] %>
<%= select_tag :engine_id, options_from_collection_for_select(@engines, "id", "name",:selected=>@car.engine_id) %>
<div><%= f.submit "Update car!" %></div>
<% end %>
当我提交表单时,出现错误 -没有路线匹配 [PUT] "/adverts"
$ rake 路线:
adverts GET /adverts(.:format) adverts#index
POST /adverts(.:format) adverts#create
new_advert GET /adverts/new(.:format) adverts#new
edit_advert GET /adverts/:id/edit(.:format) adverts#edit
advert GET /adverts/:id(.:format) adverts#show
PUT /adverts/:id(.:format) adverts#update
DELETE /adverts/:id(.:format) adverts#destroy
我需要帮助。