I asked this last week but nobody answered. Surely in the age of AJAX someone knows how to do this...
Let's say I have a Foo object, and the Foo object has Comment objects associated with it:
- I have a Foo controller, with a view displaying information about the Foo (including comments). - I have a CommentsAjaxController that contains all of the remote methods for dealing with Comments
OK, no problem. So far so good.
If the Foo page has a form that allows a comment to be added and invokes CommentsAjaxController#add_comment, how can I get that remote method to render views/foo/add_comment.rjs?
class CommentsAjaxController def add_comment render :template => 'foo/add_comment', :layout => false end end
Or--in the general case--how can I get the view conventions to work the way they always do, but to have it look for the correct view belonging to an originating controller rather than the invoked controller?
It sounds like you want to share the add_comment action across several controllers, but have different templates for each. If that's the case, the simplest solution is to just throw the add_comment action into ApplicationController. Or, for a finer-grained approach, put the add_comment method into a module and mix in the module to those controllers that need it. In that way, you get a shared action, but separate views.