# Drop down

**URL:** <https://www.ruby-forum.com/t/drop-down/193976>\
**Category:** Rails\
**Created:** [August 27, 2010, 1:36pm UTC](https://www.ruby-forum.com/t/drop-down/193976 "2010-08-27T13:36:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliver\_torres](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a9a28c/32.png) [@oliver\_torres](https://www.ruby-forum.com/u/oliver_torres)\
**Post date:** [August 27, 2010, 1:36pm UTC](https://www.ruby-forum.com/t/drop-down/193976/1 "2010-08-27T13:36:29Z")

</div>

Guys, I have a partial for a form here:

\<% form\_remote\_tag(:controller =\> “posts”, :action =\> “create”) do %\>  
\<%= label\_tag(:title, “Title”) %\>  
  
\<%= text\_area\_tag(:title, nil) %\>  
  
\<%= label\_tag(:body, “Description”) %\>  
  
\<%= text\_area\_tag(:body, nil) %\>  
  
\<%= submit\_tag(“Post”) %\>  
\<% end %\>

So I want to have a drop down where people can select what kind of  
update this is before they post it,  
something like: general or Job etc.  
On an example code I found this;

\<%= f.label :group\_ids, "Group" %\> \<%= f.collection\_select :group\_ids, Group.all(:order =\> "name ASC"), :id, :name %\>

Wich basically renders a drop down menu with all “Groups”  
Im my case I need to do something like this:

\<%= f.label :update\_type, "Post" %\> \<%= f.collection\_select :update\_type, Post.all(:order =\> "name ASC"), :id, :name %\>

except, I dont have a local variable f on my partial on the first  
chuck of code above.  
so what is the syntax to change my last last piece of code to work  
with the partial above so I  
can effectively render a drop down that will let me select the  
update\_type ?

any help will be great.  
Oliver.

---

<div class="post-metadata">

**Author:** ![oliver\_torres](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a9a28c/32.png) [@oliver\_torres](https://www.ruby-forum.com/u/oliver_torres)\
**Post date:** [August 27, 2010, 8:43pm UTC](https://www.ruby-forum.com/t/drop-down/193976/2 "2010-08-27T20:43:21Z")

</div>

collection\_select is build around an object, that’s why in the example  
they  
use f.collection\_select, but you are using helpers with tag sufix, you  
don’t  
need an object in order to use those kind of helpers, so… maybe you  
should  
use select\_tag:

_select\_tag_(name, option\_tags = nil, options = {})

you pass it a option\_tags collection, you can get it from:

_options\_for\_select_(container, selected = nil)

you pass it an array of options or a hash, and if you want an option to  
be  
selected as default… then you pass it also

your example should look something like:

\*select\_tag(‘name’, options\_for\_select(\*Post.all(:order =\> “name  
ASC”).collect {|p| [p.name, p.id]} _))_

2010/8/27 oliver torres [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![oliver\_torres](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/a9a28c/32.png) [@oliver\_torres](https://www.ruby-forum.com/u/oliver_torres)\
**Post date:** [August 27, 2010, 9:07pm UTC](https://www.ruby-forum.com/t/drop-down/193976/3 "2010-08-27T21:07:02Z")

</div>

oliver torres wrote:

> Guys, I have a partial for a form here:

[…]

> So I want to have a drop down where people can select what kind of  
> update this is before they post it,  
> something like: general or Job etc.  
> On an example code I found this;
> 
> \<%= f.label :group\_ids, "Group" %\> \<%= f.collection\_select :group\_ids, Group.all(:order =\> "name ASC"), :id, :name %\>
> 
> Wich basically renders a drop down menu with all “Groups”  
> Im my case I need to do something like this:
> 
> \<%= f.label :update\_type, "Post" %\> \<%= f.collection\_select :update\_type, Post.all(:order =\> "name ASC"), :id, :name %\>
> 
> except, I dont have a local variable f on my partial on the first  
> chuck of code above.

Right, because form\*\_tag doesn’t create a FormBuilder object.

> so what is the syntax to change my last last piece of code to work  
> with the partial above so I  
> can effectively render a drop down that will let me select the  
> update\_type ?

If you had read the docs for collection\_select, you would have found  
that it takes one more argument when no FormBuilder is involved. If  
that syntax doesn’t work in your particular case, select\_tag (and  
perhaps options\_from\_collection\_for\_select ) will.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
