Skip to content

Instantly share code, notes, and snippets.

@kristianhellquist
Created October 5, 2012 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristianhellquist/3839833 to your computer and use it in GitHub Desktop.
Save kristianhellquist/3839833 to your computer and use it in GitHub Desktop.
Nested resources
# config/routes.rb
resources :contacts do
resources :labels
end
# app/controllers/network/labels_controller.rb
class Network::LabelsController
def index
responds_with(scope)
end
def show
responds_with(scope.find(params[:label_id]))
end
protected
def scope
if params[:contact_id]
current_pressroom.contacts.find(:contact_id).labels
else
current_pressroom.labels
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment