want to create the ability to say “if logged_in?” instead of “if session.key[rider.id]?”
How and where is that done so that I test it from controller and views code.
Thanks in advance.
want to create the ability to say “if logged_in?” instead of “if session.key[rider.id]?”
How and where is that done so that I test it from controller and views code.
Thanks in advance.
What have you tried so far?
If you need a controller method to be visible as a view helper, that is usually done with the helper_method
macro in your controller class. AbstractController::Helpers::ClassMethods
If you want to access this method on any page in your app, I would consider adding this to your ApplicationController, since all other controllers inherit from that.
Be sure to handle the lack of a session, so this doesn’t blow up on a first page load somewhere you don’t anticipate.
Walter
What authenticator do you use?
I use before_action :authenticate_user!
with Devise, in my application controller. If I understand well Rails 8 authenticator, you may also test if your user is authenticated with the helper method :authenticated?
(source: rails/railties/lib/rails/generators/rails/authentication/templates/app/controllers/concerns/authentication.rb.tt at 8-0-stable · rails/rails · GitHub)
Maybe those tracks (not sure of the good word to use here) can help you.