私は一種のオークション/寄付プロジェクトに取り組んでおり、製品の属性を変更したいと考えています。これは、製品が寄付されたことを示すブール値です。
私が今やっている方法は次のとおりです。
意見:
<%= form_for(@product) do |f| %>
<%= f.label "Are you sure you want to get this product?"%>
<%= f.check_box :donated%>
<%= f.submit "Receive!", class: "btn btn-large btn-primary" %>
<% end %>
コントローラ:
before_filter :signed_in_user, only: [:create, :destroy, :show, :index, :update]
...
def update
@product.update_attributes(params[:product])
flash[:success] = "Product donated!"
end
ルート:
resources :products, only: [:show, :create, :new, :update]
そして、次のエラーが発生します。
undefined method `update_attributes' for nil:NilClass
app/controllers/products_controller.rb:30:in `update'
Request
Parameters:
{"utf8"=>"✓",
"_method"=>"put",
"authenticity_token"=>"M9q/qVcDmVIlEx+T5VFF0YtkYtzHRUCZLkPkDjc7MJc=",
"product"=>{"donated"=>"1"},
"commit"=>"Update product",
"id"=>"1"}
私は何を間違っていますか?ありがとうございます。