Felix Felix - 4 years ago 187
Ruby Question

Ruby on Rails collection output in collection_select

I've got this code:

<%= collection_select :channel, @channelList, :id, :channelname, {prompt: (t "channel.add.prompt")}, class: "form-control"%>

And got this error:

enter image description here

Its a normal active relation

enter image description here

Whats my mistake in this case?


Answer Source


You have to specify: object, method, collection, value_method, text_method, you probably forgot to set the object param.

Which would make this:

<%= collection_select :object, :channel, @channelList, :id, :channelname, {prompt: (t "channel.add.prompt")}, class: "form-control"%>

(replace :object with your object you want to save the channel to)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download