# Populating dropdowns REST-style

**URL:** <https://www.ruby-forum.com/t/populating-dropdowns-rest-style/138053>\
**Category:** Rails\
**Created:** [May 19, 2008, 9:52pm UTC](https://www.ruby-forum.com/t/populating-dropdowns-rest-style/138053 "2008-05-19T21:52:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahead](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c77e96/32.png) [@ahead](https://www.ruby-forum.com/u/ahead)\
**Post date:** [May 19, 2008, 9:52pm UTC](https://www.ruby-forum.com/t/populating-dropdowns-rest-style/138053/1 "2008-05-19T21:52:03Z")

</div>

Resource A and B are nested. In the form for C, I need to populate a  
dropdown of B:s depending on the value of A.

Trying to be RESTful, my approach is to have an onchange-handler on the  
A dropdown which calls the index action of B and redraws the B dropdown  
using RJS and a partial.

My concern is that because the RJS and partial should generate a  
select-helper for editing C, the code in the “B domain” (controller,  
RJS, partial) needs to be C-aware which feels ugly…

Does anybody have an alternative design which makes this cleaner  
somehow?

Another (perhaps silly) question. If I use the form builder object in  
the partial for B, it seems hard to reuse it from RJS because I don’t  
have a form builder object there. Or should I skip the form builder for  
the B dropdown and use the instance variable instead? (Similar to how  
scaffolding in earlier version of Rails did it)

Wow, that’s a long and somewhat strange post. I’m impressed that you  
made it to the end! 😉

---

<div class="post-metadata">

**Author:** ![ahead](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c77e96/32.png) [@ahead](https://www.ruby-forum.com/u/ahead)\
**Post date:** [May 20, 2008, 12:24am UTC](https://www.ruby-forum.com/t/populating-dropdowns-rest-style/138053/2 "2008-05-20T00:24:21Z")

</div>

Hi, I’ve only just finished writing a tutorial on exactly this:

> **[frozenplague.net](http://frozenplague.net/2008/05/20/updating-a-select-box-based-on-another/)**
>
> This domain may be for sale!

## Enjoy.

Appreciated my help?  
Reccommend me on Working With Rails  
[http://workingwithrails.com/person/11030-ryan-bigg](http://workingwithrails.com/person/11030-ryan-bigg)
