Created
June 15, 2013 15:48
-
-
Save Olgagr/5788534 to your computer and use it in GitHub Desktop.
Controller private setter for local variable
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 FollowingRelationshipsController < ApplicationController | |
def create | |
current_user.follow user | |
redirect_to user | |
end | |
def destroy | |
current_user.unfollow user | |
redirect_to user | |
end | |
private | |
def user | |
@_user ||= User.find(params[:user_id]) # memoize searching in instance variable | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment