# AJAX and RESTful routes

**URL:** <https://www.ruby-forum.com/t/ajax-and-restful-routes/175921>\
**Category:** Rails\
**Created:** [September 22, 2009, 8:59pm UTC](https://www.ruby-forum.com/t/ajax-and-restful-routes/175921 "2009-09-22T20:59:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [September 22, 2009, 8:59pm UTC](https://www.ruby-forum.com/t/ajax-and-restful-routes/175921/1 "2009-09-22T20:59:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oldbug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/c0e974/32.png) [@oldbug](https://www.ruby-forum.com/u/oldbug)\
**Post date:** [September 22, 2009, 10:00pm UTC](https://www.ruby-forum.com/t/ajax-and-restful-routes/175921/2 "2009-09-22T22:00:16Z")

</div>

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](http://www.marnen.org)  
removed\_email\_address@domain.invalid
