Make a note of the useful helper methods you can use when deploying devise.
Method | function |
---|---|
before_action :authenticate_user! | Allow access only to logged-in users |
current_user | Get the currently logged in user |
user_signed_in? | Determine if the user is signed in |
user_session | Access user session information |
3.before_action :authenticate_user! This method switches the page to be displayed depending on the login status. If the user is not logged in, the user will be transitioned to the login screen. By calling before_action, you can transition to the login screen if you have not logged in before executing the action.
app/controllers/application_controller.rb
class ArticlesController < ApplicationController
before_action :authenticate_user!
def index
end
def show
end
end
Recommended Posts