Collect_select conditional options={}

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs