this is my before_action
in controller
before_action :redirect_to_home, unless: :logged_in?, only: %i[destroy]
before_action :redirect_to_home, if: :logged_in?, only: %i[new create]
My purpose is redirect to home when call new
and create
action for authenticated user and destroy
for unauthenticated user
this is my redirect_to_home
callback
def redirect_to_home
redirect_to root_path
end
this is my logged_in?
method
def logged_in?
p 'HELLO FROM LOGGED_IN'
session[:user_id].present?
end
when I ran the destroy
test spec nothing printed out to the console but when I swap the line and run the destroy
test spec again everything looks fine but new
and create
test spec are broken.
Do you guys have any ideas?
Thanks