我正在尝试创建一个集合选择,但我收到了这个错误:
NoMethodError in Deal#selectuser
undefined method `to_key' for #<Conversation::ActiveRecord_Relation:0x1059f4f8>
我的控制器
def selectuser
@conversation = Conversation.involving(current_user)
end
我的路线
resources :deal, only: [:index, :new, :create, :selectuser] do
collection do
get "selectuser" # generate get "/deal/selectuser"
end
我的观点(conversation.html.erb)
<%= form_for @conversation do |f| %>
<%= collection_select(:conversation, :recipient_id, Conversation.all, :recipient_id, :title) %>
<%= f.submit "Send", class: "btn btn-primary wide" %>
答案 0 :(得分:0)
您需要将collection_select
方法编写为:
<%= f.collection_select :recipient_id, Conversation.all, :recipient_id, :title %>