Devise :: :: In Rails with the Link of If and else.
Devise :: Pdf is also attached in this link :: You can check this tutorial and devise will successsfully run in your application definately.
....................................................
1. Add gemfile of devise gem in gemfile ::
1. Add this devise gemcode in your gemfile and bundle update or bundle
command run at terminal
gem ‘devise’
bundle
2. Set up devise in your App ::
Run this Command at your Terminal
rails g devise:install
3. Configure Devise :: First do this then give the command of rails g devise:install
Write this code in the config/enviornments/development.rb
config.action_mailer.default_url_options={host:’localhost’,port:3000}
4. Setup User Model ::
rails g devise user or rails g devise user --force
rails db:migrate
5. Make the controller with the action
rails g controller home index
6. Set Path route and Default Route ::
get 'home/index'
root to :home#index
7. Create the First User ::
http:://localhost:3000/users/sign_up and create your Account
8. Add Sign Up and Login Links ::
app/views/layout.application.html.erb ::
<p class="navbar-text float-right">
<% if user_signed_in? %>
Logged in as <strong><%= current_user.email %></strong>
<%= link_to 'Edit Profile',edit_user_registration_path, :class=> 'navbar-link' %>|
<%= link_to "Logout", destroy_user_session_path, method: :delete, :class=>'navbar-link'
%>
<% else %>
<%= link_to "Sign up", new_user_registration_path, :class=>'navbar-link' %>
<%= link_to "Login", new_user_session_path, :class=>'navbar-link' %>
<%end%>
9. If User is not Signed in then force User to redirect to the Login Page::
before_action :authenticate_user!
Comments
Post a Comment