ruby on rails - How redirect to a sign in page when the user is not authenticated -
i want add together in action 'destroy' if/else user not logged, redirect signin page, i'm doing wrong.
def destroy if user.sign_in sign_out redirect_to root_url else redirect_to signin_path end end
helper sessions_helper
def sign_in(user) remember_token = user.new_remember_token cookies.permanent[:remember_token] = remember_token user.update_attribute(:remember_token, user.encrypt(remember_token)) self.current_user = user end
how prepare it? sorry bad english
in destroy method phone call user.sign_in
in helper have definition sign_in(user)
have prepare using:
user.sign_in
and creating method on class user
or:
sign_in(user)
passing user param actual method defined.
edited
applicationcontroller def sign_in(user) remember_token = user.new_remember_token cookies.permanent[:remember_token] = remember_token user.update_attribute(:remember_token, user.encrypt(remember_token)) self.current_user = user end end
ruby-on-rails
No comments:
Post a Comment