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/.
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 differentways.Messages.find(:all, :conditions => ["to_user_id = ?, @me] for inbox, andso on.Any thoughts on how I can make this RESTful? More models perhaps?filters?
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.
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.