user984621
user984621

Reputation: 48453

Rails - new path doesn't work. Why?

I need to have the URL like photos/13/rate => I have created following routing rule:

match 'photos/:id/rate' => 'photos#rate'

In this case I would assume this path:

link_to 'Rate', rate_photos_path(@photo)

But I am still getting the error message

undefined method `rate_photo_path' for #<#<Class:0x0000012aa18170>:0x0000012aa14520>

I tried to print out rake:routes, but in the statement is only

                       /photos/:id/rate(.:format)                    photos#rate

without the path.

What's wrong in this case?

Upvotes: 0

Views: 861

Answers (1)

xdazz
xdazz

Reputation: 160863

Try this:

resources :photos do
  member do
    get 'rate'
  end
end

Or you need to give the route a name.

match 'photos/:id/rate' => 'photos#rate', :as => :rate_photo

Upvotes: 1

Related Questions