mercredi 5 décembre 2018

Handling session in rails

The admin has the rights to activate deactivate user account. example image link https://imgur.com/a/S9wEsQY only activated user should be login that scenario has been completed successfully(used Boolean datatype admin=true&user=false).activated user have longed in browser if admin has deactivated her account.user should not do anything automatically leave to login page how to do it?devise gem used

routes.rb

root to: 'application#home', as: :root   
  devise_for :users, controllers: { sessions: 'users/sessions',
                    registrations: 'users/registrations'
                  }

controller# application_controller.rb

class ApplicationController < ActionController::Base
    before_action :authenticate_user!
def home
end
end

model# user.rb

def is_admin?
     role == 0
    end

    def is_user?
        role == 1
    end

view# home.html.erb

<%if  current_user.is_admin?%>
<%=  render 'layouts/admin' %>
      <%else%>
<%=  render 'layouts/user' %>
<% end %>

Aucun commentaire:

Enregistrer un commentaire