code at first
# application.rb
def current_user
User.find(session[:user_id])
end
# application.rb
def current_user
@current_user ||= User.find(session[:user_id])
end
For the first one every time when the function is called it will create new instance to the database.
For the second one uses caching with or symbol which will only excutes the code when instance variable is not ready.next time it will returns the value
This article was taken from rails cast for my studying purpose
No comments :
Post a Comment