Felix Felix - 7 months ago 13
Ruby Question

rails .find returns a special unkown error

In my form I have this selection field.

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


Looks perfekt and displays a selection with all the availabe channels.

Now I want to find it with the .find function after sending form. Code looks like this:

@channel = Channel.find(params[:channel_id])
@vid.channel = @channel


In params the channel_id is display with id correctly ... but I got this error:

enter image description here

Whats the problem in this case? Don't understand it ...

Thanks for your help.

EDIT - params

enter image description here

Answer

Couldn't find Channel with 'id'=

When you look at the params, you got channel_id inside vid hash. So you can't access it with params[:channel_id]. You should do the below

@channel = Channel.find(params[:vid][:channel_id])