Ruby on Rails Monday, May 29, 2017

On 29 May 2017 at 14:32, Walter Lee Davis <waltd@wdstudio.com> wrote:
>
>> On May 29, 2017, at 3:59 AM, Colin Law <clanlaw@gmail.com> wrote:
>>
>> On 28 May 2017 at 23:26, fugee ohu <fugee279@gmail.com> 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 <fuge...@gmail.com> 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.

You are right of course. I am getting old :(

Colin

>
> http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-form_tag
>
> 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.
>
> Walter
>
> --
> 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 rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/2FCF702E-E978-429C-999C-34B20FD514AC%40wdstudio.com.
> For more options, visit https://groups.google.com/d/optout.

--
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 rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLsYoU5KVUDfFWZRjhO8FxThkUe4gL0TSO9cJYk7Efd2%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment