adding a drop down menu to index view

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

adding a drop down menu to index view

fugee ohu
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>

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/8cb2b9d3-853f-4fec-87a2-e15fed097c68%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: adding a drop down menu to index view

Chris Lerum
try <%= f.collection_select( :artist, :genre_id, Genre.all, :id, :name) %>

On Sunday, May 28, 2017 at 4:17:53 PM UTC-4, 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>

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/47a9dff5-9513-40d7-ada5-f315ce4fdfd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: adding a drop down menu to index view

fugee ohu


On Sunday, May 28, 2017 at 4:28:35 PM UTC-4, Chris Lerum wrote:
try <%= f.collection_select( :artist, :genre_id, Genre.all, :id, :name) %>

On Sunday, May 28, 2017 at 4:17:53 PM UTC-4, 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>


gets me the same error, the  object is plural @artists, there's no form_for @artists instead i'm using <%= form_tag(artists_path) do |f| %>

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/86014fc8-fffa-43a4-926a-ab8aa5ae73b5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: adding a drop down menu to index view

Colin Law
In reply to this post by fugee ohu
On 28 May 2017 at 21:17, fugee ohu <[hidden email]> 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

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLtRuu1Nn7SSBss5Jvt%2BLmxMPbYT%3DVFPR0A1-fY27Sa%3DJQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: adding a drop down menu to index view

fugee ohu


On Sunday, May 28, 2017 at 4:58:13 PM UTC-4, Colin Law wrote:
On 28 May 2017 at 21:17, fugee ohu <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="mY5thsiJCgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">fuge...@...> 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| %>
 

--
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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/1340f13b-8e7c-4e81-a63d-e28833acf816%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: adding a drop down menu to index view

Colin Law
On 28 May 2017 at 23:26, fugee ohu <[hidden email]> 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 <[hidden email]> 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

>
>
> --
> 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 [hidden email].
> To post to this group, send email to [hidden email].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/1340f13b-8e7c-4e81-a63d-e28833acf816%40googlegroups.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 [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLs6LG9Ranzd_8H3o%2BcMSN6Td7%3Dqqxvj9UEQ0qqbNLQO9A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: adding a drop down menu to index view

Walter Lee Davis

> On May 29, 2017, at 3:59 AM, Colin Law <[hidden email]> wrote:
>
> On 28 May 2017 at 23:26, fugee ohu <[hidden email]> 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 <[hidden email]> 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.

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 [hidden email].
To post to this group, send email to [hidden email].
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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: adding a drop down menu to index view

Colin Law
On 29 May 2017 at 14:32, Walter Lee Davis <[hidden email]> wrote:

>
>> On May 29, 2017, at 3:59 AM, Colin Law <[hidden email]> wrote:
>>
>> On 28 May 2017 at 23:26, fugee ohu <[hidden email]> 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 <[hidden email]> 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 [hidden email].
> To post to this group, send email to [hidden email].
> 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 [hidden email].
To post to this group, send email to [hidden email].
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.
Loading...