Rails 3 - Dealing with Model Inheritance? Books > Authors, not Books & Authors
I have two models: Books and Authors. Books has_many Authors Authors belongs_to Books
Problem is right now this loads in my app: /books /authors
I don't want users to be able to look at /autho开发者_Go百科rs
The behavior I want is users to first select a Book and get all kinds of great book detail... Then the user can click "Show me all the book's authors" to go to something like: /books/10/authors/
And since authors can't exist outside of a book, to view a author: /books/10/authors/1
And in this case, authors can't belong to multiple books, just one book (trust me!)
Solutions, Ideas? thank you
I would look at nested resources for your routes. Your can define this in your routing file like so:
resources :books do
resources :authors
end
Now users won't be able to access just /authors. They will need to go to /books/1/authors
More here: http://edgeguides.rubyonrails.org/routing.html#nested-resources
精彩评论