In a nutshell:
I’ve got 2 RESTful resources and complex edit page for the parent
resource. I want to modify the nested resource from the parent
resource’s edit page, and I want to use AJAX to do it. I’m having a
really hard time finding a clean way to organize the RJS and partials
I’m writing a RESTful Rails app and I’m bumping into almost exactly
the same xhr context problem described at the very end of this post…
…and in this July, 2006 blog post from Bruce W…
Question 1: Have there been any additions to core Rails that address
this context problem?
More than anything, I feel like this context issue has introduced a
lot of codebase uncleanliness. Uber-quick example:
I have a Foo resource with a nested Bar resource.
From a form in foos/show.rhtml, I want to update the nested Bar
resource via BarsController:update.
Great…so, I hit the update action in the BarsController. In my
respond_to, I do a switch on the appropriate context and then render a
Question 2: Where should these context-specific RJS files live? Under
views/bars or views/foos?
I think the common approach would be for (say) update_context1.rjs to
live under views/bars. It really bugs me, though, that this file is
going to contain a div id for some div that is only relevant in the
Foo’s view (a la 'page.replace_html
Alternatively, one could drop an update_bar_context1.rjs in views/
foos. The div id contained therein will reference some div relevant
to Foo, which is nice, but having the BarsController reference an RJS
outside of its own view space likewise seems a bit dirty.
I have to think that there are others out there who are doing some
AJAX-heavy nested resource editing. What pattern(s) have you
followed? You know, I don’t actually own the Recipes book. Is there
a Recipe in there for this scenario?
Thanks in advance, all.