This is a memorandum when the ** guest login function ** was added so that you can log in with the touch of a button to make it easier to see the contents when creating the original application. ** devise ** is used for new registration and login functions.
def self.guest find_or_create_by!(username: 'The guests', email: '[email protected]') do |user| user.password = SecureRandom.urlsafe_base64 end end
First, set the routing.
devise_scope :user do post 'users/guest_sign_in', to: 'users/sessions#new_guest' end
new_guest, add the action to ʻusers / sessions_controller.rb
. ʻAdd the users directory to
class Users::SessionsController < Devise::SessionsController def new_guest user = User.guest sign_in user redirect_to root_path, notice: 'You have logged in as a guest user.' end end
Finally, add a view such as a button to complete the implementation.
<p class="control"> <%= link_to 'Guest login', users_guest_sign_in_path, class: "button is-warning is-fullwidth", method: :post %> </p>
Addition of a very important function to let you see the portfolio (original app). It was relatively easy to implement. Thank you for reading to the end: grin: