# Observe\_field example of two related selects

**URL:** <https://www.ruby-forum.com/t/observe-field-example-of-two-related-selects/183043>\
**Category:** Rails\
**Created:** [February 6, 2010, 8:31pm UTC](https://www.ruby-forum.com/t/observe-field-example-of-two-related-selects/183043 "2010-02-06T20:31:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![InventoryTrackers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/59ef9b/32.png) [@InventoryTrackers](https://www.ruby-forum.com/u/InventoryTrackers)\
**Post date:** [February 6, 2010, 8:31pm UTC](https://www.ruby-forum.com/t/observe-field-example-of-two-related-selects/183043/1 "2010-02-06T20:31:04Z")

</div>

I’ve done the ‘Googling’ for days now to find an example of using two  
dependent select statements on a form where the user selects the  
parent record value and the observe\_field ‘kicks in’ to create another  
select that shows parent.children offerings.  
Is there anyone I can pay to provide me with the simplest example? If  
so, please contact me by email.  
Hopeful thanks,  
David

---

<div class="post-metadata">

**Author:** ![InventoryTrackers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/59ef9b/32.png) [@InventoryTrackers](https://www.ruby-forum.com/u/InventoryTrackers)\
**Post date:** [February 7, 2010, 6:10pm UTC](https://www.ruby-forum.com/t/observe-field-example-of-two-related-selects/183043/2 "2010-02-07T18:10:49Z")

</div>

Hi David,

On Sat, 2010-02-06 at 11:29 -0800, InventoryTrackers wrote:

> I’ve done the ‘Googling’ for days now to find an example of using two  
> dependent select statements on a form where the user selects the  
> parent record value and the observe\_field ‘kicks in’ to create another  
> select that shows parent.children offerings.  
> Is there anyone I can pay to provide me with the simplest example? If  
> so, please contact me by email.

The general model, having rendered the form, is to pass the selected  
parameter back to a controller which then a) uses that value to query  
the database for the values to use for the second select and then b)  
uses rjs to render a partial containing the second select, passing the  
collection obtained in a) in via a local or via an instance variable.

Which of these steps are you having trouble with? Post the (relevant  
snippets of) code you’ve got and we can help.

Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![InventoryTrackers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/59ef9b/32.png) [@InventoryTrackers](https://www.ruby-forum.com/u/InventoryTrackers)\
**Post date:** [February 7, 2010, 6:33pm UTC](https://www.ruby-forum.com/t/observe-field-example-of-two-related-selects/183043/3 "2010-02-07T18:33:44Z")

</div>

InventoryTrackers wrote:

> I’ve done the ‘Googling’ for days now to find an example of using two  
> dependent select statements on a form where the user selects the  
> parent record value and the observe\_field ‘kicks in’ to create another  
> select that shows parent.children offerings.  
> Is there anyone I can pay to provide me with the simplest example? If  
> so, please contact me by email.

Unfortunately, it’s best not to use observe\_field. Rails’ JavaScript  
helpers mix JS into HTML, which is bad practice (Rails 3 will fix this).  
Just write the JavaScript yourself – it’s quite simple – and put it in  
an external file.

> Hopeful thanks,  
> David

Best,  
–Â  
Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid
