Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6586297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:46:24+00:00 2026-05-25T16:46:24+00:00

I have a multi-client CMS. Clients have many users and users belong to a

  • 0

I have a multi-client CMS. Clients have many users and users belong to a client. Therefore the user model has username and client_id. The username is unique within the client_id scope.

I want to allow devise to sign the user in based on the username and the client_id, however, being that client_id is an incrementing integer, I would prefer the user to not need to know his client_id. Rather he should just be able to use the client name which is an attribute of the client model.

I know I can create a method client_handle like so:

class User
   def client_handle
      self.client.handle
   end
end

is there a way I can configure devise to login using [:username, :client_handle] ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:46:25+00:00Added an answer on May 25, 2026 at 4:46 pm

    Create a client_name virtual attribute in Users:

    1. Add client_name as an attr_accessor:

      attr_accessor :client_name

    2. Add client_name to attr_accessible:

      attr_accessible :client_name

    Tell Devise to use :client_name in the authentication_keys
    Modify config/initializers/devise.rb to have:

     config.authentication_keys = [ :email, :client_name ]
    

    Overwrite Devise’s find_for_database_authentication method in Users

    For ActiveRecord:

     protected
    
     def self.find_for_database_authentication(warden_conditions)
       conditions = warden_conditions.dup
       client_name = conditions.delete(:client_name)
       email = conditions.delete(:email)
       where(conditions).where(["lower(email) = :value", { :value => email.downcase }]).where(["'user'.'client_id' in (select 'id' from 'clients' where 'clients'.'name' = :value)", {:value => client_name}]).first
     end
    

    And last step is add client_name field to views:

    Make sure you have the Devise views in your project so that you can customize them

    Rails 3:

    rails g devise:views
    

    Modify the views
    sessions/new.html.erb:

      <p><%= f.label :email %><br />
      <%= f.email_field :email %></p>
    +  <p><%= f.label :client_name %><br />
    +  <%= f.text_field :client_name %></p>
    

    *PS: Instead of your client_handle method use*

    delegate :handle, :to => :client, :prefix => true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi-user eclipse (3.4) installation with a shared master configuration area. Users
I have a multi-user application consisting of a flex client and blazeds/Spring/java backend -
I have made a custom CMS and I'd like to make it multi-client while
I have a multi-user ASP.NET app running against SQL Server and want to have
I have a multi-step form and user can navigate to any page to modify
I have a User model in my app, which I would like to store
I have a client server application with multi-threading. The server side is failing with
I have to implement a Proof of concept for multi client handling in JSF
I'm building a multi-threaded client side javascript application, and I would like to have
I have a multi threaded client server application which uses Sockets. When a new

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.