I just started looking at REST, and am working on a simple app made up
from Authors and Books with an Author has_many :books relationship.
I''m thinking the following resources make sense:
/books
books/book_id
/books/book_id/author
/authors
/authors/author_id
/authors/author_id/books
I.e. listing books, listing authors, looking up a book or author,
listing books for a certain author, and accessing the author of some
specific book.
Is this reasonable, or am I already doing something wrong? I''m
guessing that /books/book_id/author may be a little over the top.
As for routes, I now have the following:
map.resources :books do |book|
book.resource :author
end
map.resources :authors do |author|
author.resources :books
end
According to rake routes, there''s a fair amount of controller+action
duplication here.
Is this ok, should I be looking at parameters to figure out what to do?
Here''s the index action from my books controller right now. This one
isn''t too messy, but I''m sure other actions will turn out
worse..?
# GET /books[.xml]
# GET /authors/author_id/books[.xml]
def index
if params[:author_id].nil?
@books = Book.find(:all)
else
@books = Author.find(params[:author_id]).books
end
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @books }
end
end
TBH I''m a little lost, and should probably be looking for books or
something. Recommendations appreciated.
Thank you,
Isak
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
George Bray
2007-Nov-01 11:10 UTC
Re: Learning REST: Multiple routes to the same resource?
On Nov 1, 2007 9:57 PM, Isak Hansen <isak.hansen-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> TBH I''m a little lost, and should probably be looking for books or > something. Recommendations appreciated.try this one, lots of ruby examples <http://www.oreilly.com/catalog/9780596529260/> and this <http://peepcode.com/products/restful-rails> -- George Bray, Canberra, Australia --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---