Populating dropdowns REST-style

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! :wink:

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

http://frozenplague.net/2008/05/20/updating-a-select-box-based-on-another/

Enjoy.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs