[Rails] How to use authenticate_user!

Since we learned about authenticate_user !, we will output it.

What is authenticate_user!? You can understand how to use authenticate_user !.

What is authenticate_user!?

There are two main things you need to understand.

・ Devise method -Check if the user is logged in, and if not, redirect the user to the login page.

So how do you use it?

An example of how to use authenticate_user!


before_action :authenticate_user!, except: [:show, :index]

Basically used with before_action.

The meaning of the above code is Make sure the user is logged in before every action! However, if the show action and index action are called, it will be excluded. It means that · · ·

Basically, index actions and show actions can be seen in many apps even if you are not logged in. (You can see the list of tweets and the details of tweets even if you are not logged in to Twitter)

Recommended Posts

[Rails] How to use authenticate_user!
[Rails] How to use enum
[Rails] How to use enum
How to use rails join
[Rails] How to use validation
[Rails] How to use "kaminari"
[Rails] How to use Scope
[Rails] How to use gem "devise"
[Rails] How to use devise (Note)
[Rails] How to use flash messages
How to use Ruby on Rails
[Rails] How to use Active Storage
[Introduction to Rails] How to use render
[rails] How to use devise helper method before_action: authenticate_user!
How to use Map
How to use custom helpers in rails
How to write Rails
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
[Rails] How to use rails console with docker
How to use map
[Rails] How to use ActiveRecord :: Bitemporal (BiTemporalDataModel)
[Rails] How to use the map method
How to use collection_select
How to use Twitter4J
How to use MapStruct
How to use MySQL in Rails tutorial
How to use hidden_field_tag
How to use TreeSet
How to uninstall Rails
How to use identity
How to use hashes
How to use JUnit 5
[Ruby on Rails] How to use redirect_to
[Note] How to use Rails 6 Devise + cancancan
[Ruby on Rails] How to use kaminari
How to use Dozer.mapper
How to use Gradle
[Rails] How to use video_tag to display videos
[Rails] How to use helper method, confimartion
How to use org.immutables
How to use java.util.stream.Collector
How to use VisualVM
How to use credentials.yml.enc introduced in Rails 5.2
How to use Map
[Rails] How to use select boxes in Ransack
How to use rails g scaffold, functions, precautions
How to use JQuery in js.erb of Rails6
[Ruby on Rails] How to use session method
[Rails] How to use PostgreSQL in Vagrant environment
[Java] How to use Map
[rails] How to post images
How to use Chain API
[Java] How to use Map
How to use Priority Queuing
How to use java Optional
How to use Ruby return
[Rails] How to install devise