Ruby on Rails - additional restful actions in ruby on rails - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
To add RESTful routes to the current resources we can use collection or members based on the requirement.
resources :photos do
member do
get 'preview'
end
collection do
get 'dashboard'
end
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
- Creates the following routes in addition to default 7 RESTful routes
get '/photos/:id/preview', to: 'photos#preview'
get '/photos/dashboards', to: 'photos#dashboard'
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
- If we want to do this for single lines,we can use the below command:
resources :photos do
get 'preview', on: :member
get 'dashboard', on: :collection
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
- We can also add an action to the /new path
resources :photos do
get 'preview', on: :new
end
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
- The following code will create:
get '/photos/new/preview', to: 'photos#preview'
Clicking "Copy Code" button will copy the code into the clipboard - memory. Please paste(Ctrl+V) it in your destination. The code will get pasted. Happy coding from Wikitechy - ruby on rails tutorial - rails guides - ruby rails - rubyonrails - learn ruby on rails - team
Be Careful when adding actions to our RESTful routes, probably we are missing another resource!