Additional RESTful actions
suggest changeresources :photos do
member do
get 'preview'
end
collection do
get 'dashboard'
end
end
This creates the following routes in addition to the default 7 RESTful routes:
get '/photos/:id/preview', to: 'photos#preview'
get '/photos/dashboard', to: 'photos#dashboard'
The same routes can be declared on one line each:
resources :photos do
get 'preview', on: :member
get 'dashboard', on: :collection
end
You can also add an action to the /new path:
resources :photos do
get 'preview', on: :new
end
Which will create:
get '/photos/new/preview', to: 'photos#preview'
Be mindful when adding actions to your RESTful routes. You may be missing another resource.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents