简体   繁体   中英

Rails5 and Devise: Login form for multiple models

I have two models: user and employee_user , how can I setup a login form to authenticate two models at the same time? I need to login form check in what model he needs to authentiate the user

ApplicationHelper

module ApplicationHelper
  def resource_name
    :user
  end

  def resource
    @resource ||= User.new
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end
end

Form

<%= form_for(:user, :url => session_path(:user)) do |f| %>

      <%= f.email_field :email, required: true, placeholder: "Email" %>
      <%= f.password_field :password, autocomplete: :off, required: true, placeholder: "Password" %>

      <%= f.submit 'ENTER', class: "btLogin" %>

      <div class="infosLembrar">
        <p><%= f.check_box :remember_me %> Remember me</p>
      </div>

    <% end %>

Someone already did it before? Thanks!

Devise has a wiki on this. Please check: How to Setup Multiple Devise User Models

Hope this helps!

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