Ruby on Rails Monday, May 29, 2017

> On May 29, 2017, at 3:59 AM, Colin Law <> wrote:
> On 28 May 2017 at 23:26, fugee ohu <> wrote:
>> On Sunday, May 28, 2017 at 4:58:13 PM UTC-4, Colin Law wrote:
>>> On 28 May 2017 at 21:17, fugee ohu <> wrote:
>>>> I wanna add a dropdown menu to my index view for the index action of my
>>>> artists_controller Trying to use collection_select but it responds
>>>> undefined
>>>> method `collection_select' for nil:NilClass The idea is to list artists
>>>> by
>>>> genre
>>>> <div class="field"> <%= f.collection_select( :artist, :genre, Genre.all,
>>>> :id, :name) %> </div>
>>> How are you setting f?
>>> Colin
>> <%= form_tag(artists_path) do |f| %>
> form_tag must be used inside a form, it does not create a form
> Colin

No, form_tag creates a form tag, unbound to any model object.

I think where the OP may be getting off track is that the form created by form_tag doesn't have a bound object, so saying f.collection_select is sort of meaningless. That syntax is used when you bind the form to an object, such as when you use form_for(@foo). You can use collection_select with or without an object, in the latter form, you have to provide the object as the first argument, but when you use the f.collection_select syntax, that first argument becomes the second argument, and the first argument is picked up from the f reference.

I think, ultimately, that's what's going on here -- the entire set of arguments to the helper are being shifted left one step, and the meaningless reference to the form builder (without bound object) is being passed in to the tag helper.


You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment