简体   繁体   中英

Two different login pages for one model with devise on rails

I am working on an rails app in which there is one table Users , which has two roles Admin and member. Until now I am using single login page.

But now, I need to make two different login pages with completely different styling for admin and member. Moreover Admin don't have sign_up option but member has.

I am totally confused that is it possible or not? If possible, how to achieve this.

Devise sign in form is just a form with action matching to devise controller.

You can write this form code anywhere you like,

<%= form_for(:user, :url => session_path(:user)) do |f| %>
  <%= f.text_field :email %>
  <%= f.password_field :password %>
  <%= f.check_box :remember_me %>
  <%= f.label :remember_me %>
  <%= f.submit 'Sign in' %>
  <%= link_to "Forgot your password?", new_password_path(:user) %>
<% end %>

Adding to @maximus answer, you could use the Pundit gem to define your logged in :user action through a UserPolicy controller. Within this controller, you should be able to define which direction a passed in User navigates to defined by their logged in role .

https://github.com/elabs/pundit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM