# REST w/ multiple views

**URL:** <https://www.ruby-forum.com/t/rest-w-multiple-views/143810>\
**Category:** Rails\
**Created:** [July 22, 2008, 11:16pm UTC](https://www.ruby-forum.com/t/rest-w-multiple-views/143810 "2008-07-22T23:16:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Joslyn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@Mike\_Joslyn](https://www.ruby-forum.com/u/Mike_Joslyn)\
**Post date:** [July 22, 2008, 11:16pm UTC](https://www.ruby-forum.com/t/rest-w-multiple-views/143810/1 "2008-07-22T23:16:25Z")

</div>

I have app that will need to be able to display records matching a  
search  
criteria. What is the RESTful way to do this? Just an plain index action  
with search parameters? Should the query parameters be built into the  
route?

Additionally, the records themselves will have multiple views associated  
with them, ie: html & graphs, but all via a webpage. Would responds\_to  
be  
the proper way to approach this?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Mike\_Joslyn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@Mike\_Joslyn](https://www.ruby-forum.com/u/Mike_Joslyn)\
**Post date:** [July 23, 2008, 4:19pm UTC](https://www.ruby-forum.com/t/rest-w-multiple-views/143810/2 "2008-07-23T16:19:47Z")

</div>

Mike,

If you can, also check out the Rails Recipes book. One of the recipes  
is how to write a search controller and actions that are modular and  
can be shared across multiple other controllers.

---

<div class="post-metadata">

**Author:** ![Mike\_Joslyn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@Mike\_Joslyn](https://www.ruby-forum.com/u/Mike_Joslyn)\
**Post date:** [July 23, 2008, 12:58am UTC](https://www.ruby-forum.com/t/rest-w-multiple-views/143810/3 "2008-07-23T00:58:21Z")

</div>

ESPNdev - thanks alot for the info. Da-da-da Da-da-da!

On Tue, Jul 22, 2008 at 6:16 PM, removed\_email\_address@domain.invalid \<

---

<div class="post-metadata">

**Author:** ![Mike\_Joslyn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b2d939/32.png) [@Mike\_Joslyn](https://www.ruby-forum.com/u/Mike_Joslyn)\
**Post date:** [July 23, 2008, 12:17am UTC](https://www.ruby-forum.com/t/rest-w-multiple-views/143810/4 "2008-07-23T00:17:22Z")

</div>

Hey Mike

On Jul 22, 1:05 pm, “Mike Joslyn” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have app that will need to be able to display records matching a search  
> criteria. What is the RESTful way to do this? Just an plain index action  
> with search parameters? Should the query parameters be built into the route?

That’s how I would do it. Ideally you’ll have a Search object so that  
it makes writing search rules more modular and results aren’t session-  
based (and you can share them across users). Definitely include the  
parameters in the URL if for no other reason because you’ll strengthen  
your google juice.

> Additionally, the records themselves will have multiple views associated  
> with them, ie: html & graphs, but all via a webpage. Would responds\_to be  
> the proper way to approach this?

Well, for different representations responds\_to is definitely the way  
to go (json, xml, etc). You can define a custom responds\_to as this  
guy did for the iphone ([http://blog.marcslove.com/2007/6/29/respond\_to-](http://blog.marcslove.com/2007/6/29/respond_to-)  
iphone-in-rails). Users could call [http://yoursite.com/whatever.graph](http://yoursite.com/whatever.graph)

Alternatively you could create a Graph scaffold and allow users to  
access [http://yoursite.com/graphs/whatever](http://yoursite.com/graphs/whatever)

If this is too vague let me know and I’ll try to help out further…

ESPNDev
