When you use
resource :photos
rails generates automatically the CRUD routes that allow you to Create, Read, Update and Destroy photos.
Rails uses here a number of conventions for mapping those basic CRUD routes to the controller actions. For example, POST methods are associated to create() actions of your controllers.
This behavior is implemented in the module ActionDispatch::Routing::Mapper::Resources.
If you need to add a new route (for a new controller action) which is not part of the conventional CRUD set of actions, you need to specify it in the routes.rb file of your rails application.
You have two options:
a. The action affects a collection of Photo objects (similar to the index action). For this you need to add the route within the 'collection' block. This translates into a route without any :id parameter in the URL of the route.
resources :photos
collection do
get 'thumbnail'
end
end
b. The action affect only Photo object (similar to edit and destroy actions). For this you need to add the route within the 'member' block and will make you available the :id param in the controller. The resulting URL of the route will need to specify the it in
/photos/:id/my_action
resources :photos
member do
get 'gallery'
end
end
Please also have a look at http://guides.rubyonrails.org/routing.html#crud-verbs-and-actions