REST actions

0 views
Skip to first unread message

Guest

unread,
Aug 22, 2006, 12:19:20 PM8/22/06
to rubyonra...@googlegroups.com
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.

--
Posted via http://www.ruby-forum.com/.

James Stewart

unread,
Aug 22, 2006, 12:30:52 PM8/22/06
to rubyonra...@googlegroups.com
On Aug 22, 2006, at 12:19 PM, Guest wrote:
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?

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 Stewart : Freelance Web Developer


Guest

unread,
Aug 22, 2006, 1:28:40 PM8/22/06
to rubyonra...@googlegroups.com

So you're saying call a before_filter on the index action or something?

James Stewart

unread,
Aug 22, 2006, 2:12:33 PM8/22/06
to rubyonra...@googlegroups.com
For the authentication, yes.

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


James.

Guest

unread,
Aug 22, 2006, 3:07:13 PM8/22/06
to rubyonra...@googlegroups.com

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 Stewart

unread,
Aug 23, 2006, 9:08:50 AM8/23/06
to rubyonra...@googlegroups.com
On Aug 22, 2006, at 3:07 PM, Guest wrote:
> 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.

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.

Reply all
Reply to author
Forward
0 new messages