11175
(-- --)
1
I have a select list with this code:
<select name="ticket[product_id]">
<% @products.each do |product| %>
<option value="<%= product.id %>"
<%= ' selected' if product.id == @ticket.product_id %>>
<%= product.name%>
</option>
<% end %>
In this select list the user can see the product names. I think it is
possible to do that in one line. How can I do that?
I have a select list with this code:
<select name="ticket[product_id]">
<% @products.each do |product| %>
<option value="<%= product.id %>"
<%= ' selected' if product.id == @ticket.product_id %>>
<%= product.name%>
</option>
<% end %>
something like collection_select :ticket, :product_id,
@products, :id, :name
should do the trick.
Fred
Long
(Long)
3
John Smith writes:
I have a select list with this code:
<select name="ticket[product_id]">
<% @products.each do |product| %>
<option value="<%= product.id %>"
<%= ' selected' if product.id == @ticket.product_id %>>
<%= product.name%>
</option>
<% end %>
In this select list the user can see the product names. I think it
is
possible to do that in one line. How can I do that?
I beleive the SELECT ActionView Helper is what you are looking for.
-- Long
http://FATdrive.tv/wall/trakb/10-Long
http://FATdrive.tv/ - store, play, share