# REST actions

**URL:** <https://www.ruby-forum.com/t/rest-actions/65973>\
**Category:** Rails\
**Created:** [August 22, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/rest-actions/65973 "2006-08-22T18:19:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 22, 2006, 6:19pm UTC](https://www.ruby-forum.com/t/rest-actions/65973/1 "2006-08-22T18:19:20Z")

</div>

I know DHH said anything can fit into the seven actions if you think  
about it enough but, my current delimma has me thinking otherwise.

So I’m doing an internal messaging system. The user will have an inbox,  
sent, deleted etc. To show these I need to query the data in different  
ways.

Messages.find(:all, :conditions =\> ["to\_user\_id = ?, @me] for inbox, and  
so on.

Any thoughts on how I can make this RESTful? More models perhaps?  
filters?

Thanks.

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 22, 2006, 6:58pm UTC](https://www.ruby-forum.com/t/rest-actions/65973/2 "2006-08-22T18:58:53Z")

</div>

On Aug 22, 2006, at 12:19 PM, Guest wrote:

> filters?  
> I would have thought your example was a perfectly RESTful thing to  
> do, probably in your messages controller.

Providing your user authentication complies with HTTP standards, then  
scoping your queries isn’t necessarily un-RESTful.

James.

–  
James S. : Freelance Web D.  
Work : [http://jystewart.net](http://jystewart.net)  
Play : [http://james.anthropiccollective.org](http://james.anthropiccollective.org)

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 22, 2006, 7:28pm UTC](https://www.ruby-forum.com/t/rest-actions/65973/3 "2006-08-22T19:28:40Z")

</div>

So you’re saying call a before\_filter on the index action or something?

James S. wrote:

> On Aug 22, 2006, at 12:19 PM, Guest wrote:
> 
> > filters?  
> > I would have thought your example was a perfectly RESTful thing to  
> > do, probably in your messages controller.
> 
> Providing your user authentication complies with HTTP standards, then  
> scoping your queries isn’t necessarily un-RESTful.
> 
> James.
> 
> –  
> James S. : Freelance Web D.  
> Work : [http://jystewart.net](http://jystewart.net)  
> Play : [http://james.anthropiccollective.org](http://james.anthropiccollective.org)

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 22, 2006, 9:07pm UTC](https://www.ruby-forum.com/t/rest-actions/65973/4 "2006-08-22T21:07:13Z")

</div>

I’m acutally using that plugin. It’s great!

I’m not really having trouble with that though. I’m wondering how I  
should do the search for either sent, received, or deleted messages,  
based on who’s logged in, in a RESTful manner.

Without the REST stuff, I would have probably had three separate  
actions:

get\_sent\_messages  
get\_received\_messages  
get\_deleted\_messages

That doesn’t fit into the whole REST seven actions thing though. I want  
to show three different views of the data, sent, received or deleted.

Thanks James.

James S. wrote:

> For the authentication, yes.
> 
> I see that a RESTful authentication plugin was just released (haven’t  
> had a chance to try it yet):
> 
> [http://www.agilewebdevelopment.com/plugins/restful\_authentication](http://www.agilewebdevelopment.com/plugins/restful_authentication)
> 
> James.
> 
> On Aug 22, 2006, at 1:28 PM, Guest wrote:
> 
> > > scoping your queries isn’t necessarily un-RESTful.
> > > 
> > > James.
> 
> –  
> James S. : Freelance Web D.  
> Work : [http://jystewart.net](http://jystewart.net)  
> Play : [http://james.anthropiccollective.org](http://james.anthropiccollective.org)

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 22, 2006, 8:37pm UTC](https://www.ruby-forum.com/t/rest-actions/65973/5 "2006-08-22T20:37:32Z")

</div>

For the authentication, yes.

I see that a RESTful authentication plugin was just released (haven’t  
had a chance to try it yet):

[http://www.agilewebdevelopment.com/plugins/restful\_authentication](http://www.agilewebdevelopment.com/plugins/restful_authentication)

James.

On Aug 22, 2006, at 1:28 PM, Guest wrote:

> > scoping your queries isn’t necessarily un-RESTful.
> > 
> > James.

–  
James S. : Freelance Web D.  
Work : [http://jystewart.net](http://jystewart.net)  
Play : [http://james.anthropiccollective.org](http://james.anthropiccollective.org)

---

<div class="post-metadata">

**Author:** ![guest](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8dc957/32.png) [@guest](https://www.ruby-forum.com/u/guest)\
**Post date:** [August 23, 2006, 3:19pm UTC](https://www.ruby-forum.com/t/rest-actions/65973/6 "2006-08-23T15:19:24Z")

</div>

On Aug 22, 2006, at 3:07 PM, Guest wrote:

> get\_received\_messages  
> get\_deleted\_messages
> 
> That doesn’t fit into the whole REST seven actions thing though. I  
> want to show three different views of the data, sent, received or  
> deleted.

That depends whether you’d consider the different status messages as  
distinctly different resources, or whether those methods are simply  
different conditions.

If they’re different kinds of resources, you should probably use  
separate controllers for each. If it’s options for what to display,  
you could consider using a query string:

/messages/?status=sent

or you _could_ add extra methods, so long as they map to methods

map.resources :messages, :collection =\> { :sent =\> :get, :received  
=\> :get, :deleted =\> :get }

which I believe would give you:

/messages/;sent  
/messages/;received  
/messages/;deleted

James.
