AJAX and RESTful routes

Is there a standard approach to the controller actions that exist
solely to populate data do be shown in a view when using RESTful
routing?

I understand and almost appreciate the 7 actions that exist to
implement the ideas of RESTful routes in RoR, but consider a select
box whose contents change based on the contents of some other select
box. The little I’ve learned of AJAX and RoR show me how to do this
using #remote_function, but that implies that there is an action to be
invoked on the controller to implement that remote function.

I have played games with calling the #new and #edit actions and
checking for the magical parameter passed in the :with clause. Is
that what folks do? It’s nice in that it provides a graceful way to
degrade (and/or test) using normal HTTP requests with ?param=blah
tacked on the end, but it starts to look pretty ugly (to me) as
additional parameters get added. Also (what I’m running into now),
where’s the benefit of updating only one small portion of a page when
the #new action is designed to render the whole page?

If this is a FAQ, please feel free to point me at the appropriate blog
or Railscast that explains how the professionals do this.

–wpd

Patrick D. wrote:

Is there a standard approach to the controller actions that exist
solely to populate data do be shown in a view when using RESTful
routing?

I understand and almost appreciate the 7 actions that exist to
implement the ideas of RESTful routes in RoR, but consider a select
box whose contents change based on the contents of some other select
box. The little I’ve learned of AJAX and RoR show me how to do this
using #remote_function, but that implies that there is an action to be
invoked on the controller to implement that remote function.

I have played games with calling the #new and #edit actions and
checking for the magical parameter passed in the :with clause. Is
that what folks do?
[…]

It’s not what I’d do in most cases. I’d be more inclined to create a
new action than to abuse the :with parameter. Remember, the 7 common
actions are common but in no way magical. If your application is
best served by creating a controller action that isn’t one of the big 7,
by all means do it. REST is about general structure, not specific
action names.

–wpd

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]