Wednesday, February 15, 2023

HOW TO USE DEVISE GEM

$ rails new devise_app -j esbuild -css bootstrap


$ cd devise_app


$ bundle add devise


$ rails g devise:install


$ rails g devise User


$ rails g controller pages home


$ rails db:migrate


[config/routes.rb]
root 'pages#home'


[app/views/pages/home.html.erb]

<% if current_user %>
    <p>Logged in as <%= current_user.email %></p>
    <%= link_to "Logout", destroy_user_session_path, method: :delete, data: { turbo_method: :delete } %>
<% else %>
    <%= link_to "Login", new_user_session_path %>
    <%= link_to "Sign up", new_user_registration_path %>
<% end %>

🐞Source: devise

No comments:

Post a Comment