Forum: Ruby on Rails Rails: Select and html forms

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
36f6f2152b91c3cd3d1f1669d2cdb734?d=identicon&s=25 Joe Esposito (Guest)
on 2005-12-15 18:20
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?
43ec529783988dbd6fa48d6204799c9f?d=identicon&s=25 jschairb (Guest)
on 2005-12-15 20:28
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-...
43ec529783988dbd6fa48d6204799c9f?d=identicon&s=25 jschairb (Guest)
on 2005-12-15 20:36
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-...

This works, it's probably not the best implementation...but it works.

http://wiki.rubyonrails.com/rails/pages/HowtoUseFo...

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.
8bd2103202e27763ed2ce0138ef63121?d=identicon&s=25 Sandro Duarte (Guest)
on 2005-12-15 22:20
(Received via mailing list)
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@nospam.seagroatt.com> wrote:
>      10 </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@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Sandro Duarte
Analista de Sistemas
TRE-RS/SI
This topic is locked and can not be replied to.