Created
October 5, 2012 13:32
-
-
Save kristianhellquist/3839833 to your computer and use it in GitHub Desktop.
Nested resources
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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