Created
May 15, 2012 07:33
-
-
Save ayamomiji/2699765 to your computer and use it in GitHub Desktop.
resource loading patterns
This file contains 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
class PostsController | |
before_filter :load_user | |
before_filter :load_post | |
def show | |
respond_with(@post) | |
end | |
def load_user | |
@user = User.find(params[:user_id]) | |
end | |
def load_post | |
@post = @user.posts.find(params[:id]) | |
end | |
end |
This file contains 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
class PostsController | |
def show | |
respond_with(post) | |
end | |
def user | |
@user ||= User.find(params[:user_id]) | |
end | |
def post | |
@post ||= user.posts.find(params[:id]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment