現在、漫画の表紙のカタログwebアプリを作成しています。
個人が表紙を投稿して、それがトップページに乗り、不特定多数の人が見れるようになるものです。
そこで、一つ一つの作品にいいねボタンをつけようと思います。
そこで自分はラジオボタンを実装しようと思っています。
ですが以下のようなエラーになってしまいます。
当方、初心者なのでご不便をおかけしてしまうかもしれませんが、宜しくお願い致します。
view new.html.erb
<%= form_for [@favorite] do |f| %>
<label><%= f.radio_button :favorite, "1" %></label>
<label><%= f.radio_button :favorite, "2" %></label>
<% end %>
controller Reviews_controller.rb
def new
@product = Product.find(params[:product_id])
@user = current_user
@review = Review.new
@favorite = Product.select("favorite")#Productはテーブル名
end
error
NoMethodError in Reviews#new
undefined method `to_key' for #Product::ActiveRecord_Relation:0x007ff9af305588
Did you mean? to_query
to_ary
<% end %>
<%= form_for [@favorite] do |f| %> <label><%= f.radio_button :favorite, "1" %></label> <label><%= f.radio_button :favorite, "2" %></label> <% end %>
以上です。宜しくお願い致します。
あなたの回答
tips
プレビュー