Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Olgagr/5788534 to your computer and use it in GitHub Desktop.
Save Olgagr/5788534 to your computer and use it in GitHub Desktop.
Controller private setter for local variable
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