[RUBY] Rails Addition of easy and easy login function

The result you want

When you press the "Easy Login" button, Installation of a button to log in as a registered guest user.

Prerequisites

A web app based on the Rails tutorial.

things to do

  1. Create an easy_login action separately from the create action of sessions_controller for registered guest users. Pass the email.

  2. Describe the routing of easy_login in routs.rb.

  3. Install the Easy Login button in view.

  4. Created and registered in sessions_controller.rb (seeds.rb) Add an easy_login action so that you can log in as a guest user.

sessions_controller.rb


    def easy_login
      user = User.find_by(email: "[email protected]")
          log_in user #session_Predefined with helper.
          redirect_back_or user #session_Predefined with helper.
    end  
  1. Add the following in config / routes.rb

config/routes.rb


  post   '/easy_login',   to: 'sessions#easy_login'
  1. Add the following to any place in ʻapp / views / sessions / new.html.erb`

app/views/sessions/new.html.erb


<p><%= link_to "Easy login", easy_login_path, method: :post, class: 'btn btn-primary' %></p>

result

For the time being, I was able to log in as a guest user from the easy login button.

Recommended Posts

Rails Addition of easy and easy login function
Addition of guest login function
[Rails] Addition of Ruby On Rails comment function
Implementation of Ruby on Rails login function (Session)
[Note] Summary of rails login function using devise ①
Ruby on Rails <2021> Implementation of simple login function (form_with)
Implementation of Ruby on Rails login function (devise edition)
[Rails 6] Implementation of search function
[Rails] Implementation of category function
Login function implementation with rails
[Rails] Implementation of tutorial function
[Rails] Implementation of like function
Rails tutorial (6th edition) Background operation of login function
Implement login function in Rails simply by name and password (1)
Implement login function in Rails simply by name and password (2)
Implement login function simply with name and password in Rails (3)
[Rails] Implementation of CSV import function
[Rails] Implementation of image preview function
Kaminari --Added pagination function of Rails
[Rails] About implementation of like function
[Rails] Implementation of user withdrawal function
[Rails] Implementation of CSV export function
Implement simple login function in Rails
[Rails] Differences and usage of each_with_index and each.with_index
Login function
[Rails] Implementation of tag function using acts-as-taggable-on and tag input completion function using tag-it
[Rails] Function restrictions in devise (login / logout)
Rails [For beginners] Implementation of comment function
Make a login function with Rails anyway
[Rails 6] Implementation of SNS (Twitter) sharing function
[Vue.js] Implementation of menu function Implementation version rails6
[Ruby on rails] Implementation of like function
[Vue.js] Implementation of menu function Vue.js introduction rails6
Summary of basic migration knowledge rails db: rollback and column addition / deletion
Validation settings for Ruby on Rails login function
[Rails 6] Implementation of inquiry function using Action Mailer
Rails and FormData
[Rails] Implementation of image enlargement function using lightbox2
[Rails 6.0] "Easy login" implementation procedure required for portfolio
Story of implementing login function using gem sorcery
[Rails 6] Ranking function
[Rails] Implementation of retweet function in SNS application
Ruby on Rails ~ Basics of MVC and Router ~
[Rails] Category function
Rails follow function
This and that of conditional branching of rails development
Difference between member and collection of rails routes.rb
[Rails] Ranking and pagination in order of likes
[Rails] Notification function
[Rails] Add Tags that are related to has_many to Devise User (addition of function to follow tags)
Summary of frequently used commands in Rails and Docker
[Ruby on Rails] Asynchronous communication of posting function, ajax
[No.006] Rough design of organization management screen and login
[Rails] Addition of columns / Change of data type / column name
Rails CRUD function implementation ② (edited and detailed this time)
[Ruby on Rails] Implementation of tagging function/tag filtering function
[Rails] Implementation of multi-layer category function using ancestry "Preparation"
Rails application guest login function implemented (devise not used)
[Rails] Implementation of multi-layer category function using ancestry "seed"
[Rails] Volume that displays favorites and a list of favorites
[Rails] Initial setting of user-created login with devise, devise_token_auth