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 7578965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:33:30+00:00 2026-05-30T17:33:30+00:00

I’m using rails 3.2 and devise 2.0 and I’m quite new to Rails. Requirements

  • 0

I’m using rails 3.2 and devise 2.0 and I’m quite new to Rails.

Requirements

I’d like to achieve the following:

  • have 2 or more “user” models, eg. Member, Customer, Admin
  • all models share some required fields (eg. email and password)
  • each model may have some unique fields (eg. company for Customer only)
  • some fields may be shared but not have the same validation (eg. name is required for Customer but optional for Member)
  • all fields must be filled during the registration process, so the forms are different
  • the login form should be unique

Possible solutions

I googled and searched StackOverflow for quite a long time, but nothing seems right to me (I’m a Java guy, sorry 🙂 and now I’m quite confused. Two solutions came up:

Single devise user

That’s the most frequent answer. Just create the default devise User and create relations between Member–>User and Customer–>User.
My concern here is how can I achieve a customized registration process for each model? I tried different things but all ended as a mess!

Multiple devise users

This solves the custom registration process, and seems right to me, but the unique login form is a blocker. I found an answer on SO (Devise – login from two model) which suggests to override Devise::Models::Authenticatable.find_for_authentication(conditions).
That seems complicated (?) and since I’m new to rails, I’d like to know if that could work?

Thanks for your advice!

  • 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-30T17:33:32+00:00Added an answer on May 30, 2026 at 5:33 pm

    I found a way to go and I’m quite happy with it so far. I’ll describe it here for others.

    I went with the single “user” class. My problem was to achieve a customized registration process for each pseudo model.

    model/user.rb:

    class User < ActiveRecord::Base
      devise :confirmable,
           :database_authenticatable,
           :lockable,
           :recoverable,
           :registerable,
           :rememberable,
           :timeoutable,
           :trackable,
           :validatable
    
      # Setup accessible (or protected) attributes for your model
      attr_accessible :email, :password, :password_confirmation, :remember_me, :role
    
      as_enum :role, [:administrator, :client, :member]
      validates_as_enum :role
      ## Rails 4+ for the above two lines
      # enum role: [:administrator, :client, :member]
    
    end
    

    Then I adapted http://railscasts.com/episodes/217-multistep-forms and http://pastie.org/1084054 to have two registration paths with an overridden controller:

    config/routes.rb:

    get  'users/sign_up'   => 'users/registrations#new',        :as => 'new_user_registration'
    
    get  'clients/sign_up' => 'users/registrations#new_client', :as => 'new_client_registration'
    post 'clients/sign_up' => 'users/registrations#create',     :as => 'client_registration'
    
    get  'members/sign_up' => 'users/registrations#new_member', :as => 'new_member_registration'
    post 'members/sign_up' => 'users/registrations#create',     :as => 'member_registration'
    

    controllers/users/registrations_controller.rb:

    I created a wizard class which knows the fields to validate at each step

    class Users::RegistrationsController < Devise::RegistrationsController
    
        # GET /resource/sign_up
        def new
            session[:user] ||= { }
            @user = build_resource(session[:user])
            @wizard = ClientRegistrationWizard.new(current_step)
    
            respond_with @user
        end
    
        # GET /clients/sign_up
        def new_client
            session[:user] ||= { }
            session[:user]['role'] = :client
            @user = build_resource(session[:user])
            @wizard = ClientRegistrationWizard.new(current_step)
    
            render 'new_client'
        end
    
        # GET /members/sign_up
        def new_member
          # same
        end
    
        # POST /clients/sign_up
        # POST /members/sign_up
        def create
            session[:user].deep_merge!(params[:user]) if params[:user]
            @user = build_resource(session[:user])
            @wizard = ClientRegistrationWizard.new(current_step)
    
            if params[:previous_button]
                @wizard.previous
            elsif @user.valid?(@wizard)
                if @wizard.last_step?
                    @user.save if @user.valid?
                else
                    @wizard.next
                end
            end
    
            session[:registration_current_step] = @wizard.current_step
    
            if @user.new_record?
                clean_up_passwords @user
                render 'new_client'
            else
                #session[:registration_current_step] = nil
                session[:user_params] = nil
    
                if @user.active_for_authentication?
                    set_flash_message :notice, :signed_up if is_navigational_format?
                    sign_in(:user, @user)
                    respond_with @user, :location => after_sign_up_path_for(@user)
                else
                    set_flash_message :notice, :"signed_up_but_#{@user.inactive_message}" if is_navigational_format?
                    expire_session_data_after_sign_in!
                    respond_with @user, :location => after_inactive_sign_up_path_for(@user)
                end
            end
    
        end
    
        private
    
        def current_step
            if params[:wizard] && params[:wizard][:current_step]
                return params[:wizard][:current_step]
            end
            return session[:registration_current_step]
        end
    
    end
    

    and my views are:

    • new.rb
    • new_client.rb including a partial according to the wizard step:
      • _new_client_1.rb
      • _new_client_2.rb
    • new_member.rb including a partial according to the wizard step:
      • _new_member_1.rb
      • _new_member_2.rb
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I have thousands of HTML files to process using Groovy/Java and I need to
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am using JSon response to parse title,date content and thumbnail images and place
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.

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.