I’m a little confused about the purpose of doing this:
module SessionsHelper
def current_user=(user)
@current_user = user
end
end
source: http://ruby.railstutorial.org/chapters/sign-in-sign-out#code:current_user_equals
because through our controller we set @user, which has a the scope between controller, and views, so why do we need to define it explicitly?
Also, the explanation is allows for:
redirect_to current_user
how does the function current_user, know when I say redirect_to (function) im talking about @variable_path ? (in this case user_path)
more than 90% rails developers know that( and its now been the part of Rails Convention Over Configuration we can say)
When you look at rails code, and you find @user, you need to read through a couple of lines where @user is defined, to know why it is defined, whats the purpose of it. Thats not the case with current_user, as it represents the logged in user.
About your 2nd question,
when you pass any object to redirect_to, redirection happens for the url
which suppose to be a page, a ‘show’ page, detailing out object to end user
object_path or object_url make the same url