Forum: Ruby on Rails observe_field and select box

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.
98cdb2c7e471afe34f1fab10ef812570?d=identicon&s=25 jhn Vln (jimache)
on 2007-02-13 15:42
Hi everyone,

I am a newbee in RoR and i could use some help. I have a select box
populated by:

<select name = "test_company" id = "test_company">
<option selected value=test.company.to_s>Create New </option>
<%= options_for_select Company.find(:all,
    :conditions => ["name =?", test.company],
    :order => "id asc").collect{|c| [c.external_id, c.name]},
test.company.to_s %>
</select>

... and for the above select box i have an observe field that never
fires up; based on the selection of the first box the second select box
should be populated, and if "Create New" is selected a new record is to
be created.

<%= observe_field("test_company",
                  {:url => {:controller=> '/test',:action =>
'update_people'},
      :update =>"test_person",
      :loading => "Element.show('indicator')",
      :complete => "Element.hide('indicator')",
      :with => "test_company}) %>
If i use
<%= select(:test, :company
,Company.find_all_by_name(test.company.to_s).map{|c| [c.external_id,
c.name]})%>
for my first select box then the observe field works ... but i cannot
insert the "Create New" option.

What am I doing wrong?! Any help it would appreciated.

Thank you,

Sincerely,
690247bbedee9ee592827abfbc23f715?d=identicon&s=25 David Fitzgibbon (davyfitz)
on 2007-02-13 17:02
Lcn Vn wrote:
> Hi everyone,
>
> I am a newbee in RoR and i could use some help. I have a select box
> populated by:
>
> <select name = "test_company" id = "test_company">
> <option selected value=test.company.to_s>Create New </option>
> <%= options_for_select Company.find(:all,
>     :conditions => ["name =?", test.company],
>     :order => "id asc").collect{|c| [c.external_id, c.name]},
> test.company.to_s %>
> </select>
>
> ... and for the above select box i have an observe field that never
> fires up; based on the selection of the first box the second select box
> should be populated, and if "Create New" is selected a new record is to
> be created.
>
> <%= observe_field("test_company",
>                   {:url => {:controller=> '/test',:action =>
> 'update_people'},
>       :update =>"test_person",
>       :loading => "Element.show('indicator')",
>       :complete => "Element.hide('indicator')",
>       :with => "test_company}) %>
> If i use
> <%= select(:test, :company
> ,Company.find_all_by_name(test.company.to_s).map{|c| [c.external_id,
> c.name]})%>
> for my first select box then the observe field works ... but i cannot
> insert the "Create New" option.
>
> What am I doing wrong?! Any help it would appreciated.
>
> Thank you,
>
> Sincerely,

Don't know why the first one doesn't work, but if you do:

<%= select(:test, :company,
      [['Create New','Create New']] +
Company.find_all_by_name(test.company.to_s).map{|c| [c.external_id,
c.name]})%>

You should get the Create New option at the top.

Hope this helps,

Dave.
This topic is locked and can not be replied to.