Code Editor
Terminal
Web Browser
Learn
Authentication

Filters

How do these methods work?

  1. The current_user method determines whether a user is logged in or logged out. It does this by checking whether there's a user in the database with a given session id. If there is, this means the user is logged in and @current_user will store that user; otherwise the user is logged out and @current_user will be nil.
  2. The line helper_method :current_user makes current_user method available in the views. By default, all methods defined in Application Controller are already available in the controllers.
  3. The require_user method uses the current_user method to redirect logged out users to the login page.

Here's more on the ||= syntax. Here's more on the unless keyword.

Report a Bug
If you see a bug or any other issue with this page, please report it here.