The better way to pass the foreign_key value to the Rails controller
You may want to consider reading the Rails Guide on nested resources: http://guides.rubyonrails.org/routing.html#nested-resources In a nutshell: routes.rb resources :galleries do resources :pictures do end # Generates the routes: /galleries/:gallery_id/pictures pictures_controller.rb def new @gallery = Gallery.find(params[:gallery_id]) @picture = Picture.new end def create @gallery = Gallery.find(params[:gallery_id]) # gallery_id is passed in the URL @picture = @gallery.build(params[:picture]) if … Read more