Felix Felix - 4 months ago 21
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?

thanks

Answer

http://edgeapi.rubyonrails.org/classes/ActionView/Helpers/FormOptionsHelper.html#method-i-collection_select

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)

Comments