user2362462
user2362462

Reputation: 25

rails default actions are missing params in routing

Excuse me for my lame question, but i`m stuck. Plain and simple in my routes.rb file i have:

resource :books do
    resource :reviews
  end

running rake routes | grep reviews gives me:

books_reviews POST   /books/reviews(.:format)      reviews#create
 new_books_reviews GET    /books/reviews/new(.:format)  reviews#new
edit_books_reviews GET    /books/reviews/edit(.:format) reviews#edit
                   GET    /books/reviews(.:format)      reviews#show
                   PUT    /books/reviews(.:format)      reviews#update
                   DELETE /books/reviews(.:format)      reviews#destroy

My question is: where is the :id param in the show and edit actions? According to this tutorial: http://guides.rubyonrails.org/routing.html there should be "id" params in the routing, like this:

new_books_reviews GET    /books/:id/reviews/new(.:format)  reviews#new
edit_books_reviews GET    /books/:id/reviews/edit(.:format) reviews#edit
                       GET    /books/:id/reviews(.:format)      reviews#show

On top of that where are the routes for show, update and destroy actions? I think i`m missing something fundamental, because this really sucks. Running Rails 3.2.11 Thanks for the help

Upvotes: 0

Views: 254

Answers (2)

Leo Correa
Leo Correa

Reputation: 19809

Using resources over resource will make sure Rails accounts for many resources.

Your routes should look like this

resources :books do
  resources :reviews
end

Upvotes: 0

Eric S
Eric S

Reputation: 1363

Try using resources instead of resource. Rails thinks there's only one when you use the singular form and doesn't need the ID.

For more info see the "singular resource" section of the guide

Upvotes: 2

Related Questions