Skip to content

How To: Customize routes to user registration pages

george edited this page Aug 15, 2012 · 2 revisions

Imagine we have the following devise users Customer::Private and Customer::Public.

# models/customer/private.rb
# models/customer/public.rb

Setting up the controllers

In order to scope the actions of each type of user, we first create the following controllers:

# app/controllers/customer/private/registrations_controller.rb
class Customer
  class Private
    class RegistrationsController < Devise::RegistrationsController
    end
  end
end

Setting up the views

You will then have to create views for these, for example:

# views/customer/private/registrations/new.html.haml
# views/customer/public/registrations/new.html.haml

You will likely want to have a _form.html.haml partial for each.

Configuring the devise registration routes

Then in the routes file

  devise_for :private_customers, :class_name => 'Customer::Private', :controllers => {:registrations => "customer/
private/registrations", :sessions => 'main' } do
    get   "private_customer/sign_up" => "customer/private/registrations#new", :as => :private_customer_signup
    get   "private_customer/sign_in" => "main#index", :as => :private_customer_signin
  end

Similarly for public customer. Then you are ready to hit it from the view, as link_to 'register', private_customer_signup_path in the view. Enjoy!

Clone this wiki locally