# Collect\_select conditional options={}

**URL:** <https://www.ruby-forum.com/t/collect-select-conditional-options/125174>\
**Category:** Rails\
**Created:** [January 6, 2008, 5:48pm UTC](https://www.ruby-forum.com/t/collect-select-conditional-options/125174 "2008-01-06T17:48:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hiddenhippo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/65b543/32.png) [@hiddenhippo](https://www.ruby-forum.com/u/hiddenhippo)\
**Post date:** [January 6, 2008, 5:48pm UTC](https://www.ruby-forum.com/t/collect-select-conditional-options/125174/1 "2008-01-06T17:48:14Z")

</div>

Hi,

I’m trying to use a partial that acts as both the edit a view for my  
application. within this partial I have a collect\_select, for  
example,

\<%= collection\_select(myTag, :product\_id,  
@products, :id, :description, options ={ :prompt =\> “select product”},  
{  
:onChange=\>remote\_function(:update=\>div\_id,:with=\>"‘id=’+this[this.selectedIndex].value",:url=\>{:action=\>:list\_by\_product\_id,:tag=\>myTag})  
}  
) %\>

When rendering the partial for a new record item I want it to display  
“select product”, however when displaying an existing item then to  
simply show it in the list without “select product” - if I remove  
options ={ :prompt =\> “select product”} when showing an existing saved  
item the select list will default to the correct item.

So, can I conditionally set options ={ :prompt =\> “select product”}  
within the code? So far I’ve not found a way without getting sytax  
errors; I thought something like;

\<% if product.new\_record? %\>

but I just don’t know how to get all the sytax right.

any help would be appreciated.  
thanks
