Felix Felix - 7 months ago 9
Ruby Question

rails collection_select should print my collection

I got an error while trying to use collection_select ;)

I got this code in my view:

<%= f.collection_select(:channel, :channel_id, @channels, :id, :channelname, prompt: true) %>


in my controller I have this:

@channels = Channel.all


and I got this error:

undefined method `merge' for :channelname:Symbol


Whats my failure ?

Thanks at all!

Answer

According to the docs:

collection_select(method, collection, value_method, text_method, options = {}, html_options = {}) public

So therefore you should use:

<%= f.collection_select(:channel_id, Channel.all, :id, :channelname, prompt: true) %>
Comments