I''m close to getting this to work, but not quite there. I''m
trying to
implement a dropdown control, with the current choice selected.
I have the following code in the view:
5 <select id="product_product_type"
name="product[product_type]">
6 <% 7 types = ProductType.find(:all, :order =>
"product_type")
8 options_from_collection_for_select( types, :id, :product_type,
selected=@product_type_id)
9 %>
10 </select
Which renders the following:
<label for="product_product_type">Product
type</label><br/>
<select id="product_product_type"
name="product[product_type]">
<option value="2"></option>
...
<option value="6"
selected="selected">Supplies</option>
</select>
However, in the browser the "Supplies" item isn''t displaed on
load, but
the blank first option is. Anyone see what I''m doing wrong?
--
Posted via http://www.ruby-forum.com/.
Joe, I found this thread on another list, I''m working on it now...I''ll let you know if I come up with a working solution. http://wrath.rubyonrails.org/pipermail/rails/2005-January/001905.html -- Posted via http://www.ruby-forum.com/.
jschairb wrote:> Joe, > > I found this thread on another list, I''m working on it now...I''ll let > you know > if I come up with a working solution. > > http://wrath.rubyonrails.org/pipermail/rails/2005-January/001905.htmlThis works, it''s probably not the best implementation...but it works. http://wiki.rubyonrails.com/rails/pages/HowtoUseFormOptionHelpers look for the section called ''A collection_select like helper'' I copied that code into application_helper.rb and then used his view implementation. Worked for me, although I had to change the last part in the view from : @page.section_id to just page.section_id Hopefully this will get you going. Later. -- Posted via http://www.ruby-forum.com/.
Try this:
<%= collection_select(:product, :product_type, types, :id,
:product_type, { :include_blank => true }) %>
It works fine for me.
SandroDS
On 12/15/05, Joe Esposito
<esposj-ZXLX9LArD1YAHv6IxK7/ZFaTQe2KTcn/@public.gmane.org>
wrote:> I''m close to getting this to work, but not quite there.
I''m trying to
> implement a dropdown control, with the current choice selected.
> I have the following code in the view:
>
> 5 <select id="product_product_type"
name="product[product_type]">
> 6 <%> 7 types = ProductType.find(:all, :order =>
"product_type")
> 8 options_from_collection_for_select( types, :id, :product_type,
> selected=@product_type_id)
> 9 %>
> 10 </select
>
> Which renders the following:
>
> <label for="product_product_type">Product
type</label><br/>
> <select id="product_product_type"
name="product[product_type]">
> <option value="2"></option>
> ...
> <option value="6"
selected="selected">Supplies</option>
> </select>
>
>
> However, in the browser the "Supplies" item isn''t
displaed on load, but
> the blank first option is. Anyone see what I''m doing wrong?
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
--
Sandro Duarte
Analista de Sistemas
TRE-RS/SI