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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:33:44+00:00 2026-05-20T23:33:44+00:00

Rails 2.3.9 Devise 1.0.8 I’m trying to restrict registrations for a Devise User model

  • 0

Rails 2.3.9
Devise 1.0.8

I’m trying to restrict registrations for a Devise User model to users with an admin role.

Unfortunately I’m stuck with Devise 1.0.8 and Rails 2.3.9.
I’ve read the methods outlined in the Devise wiki about namespacing seperate Users::Registrations controller, and so far I’ve managed to get to the stage were the Users::Registrations controller is rendering a new user form – however on submission the form goes to the original Devise Registrations controller and the [:require_no_authentication] filter (which is skipped in the Users::Registrations controller) fires and redirects to the home page (due to the User already being logged in as an Admin).

I think this is an issue with the routes but I’m kinda stumped – most of the Google’d answers and suggestions are for Devise with Rails 3. Any ideas?

 Processing Users::RegistrationsController#new (for 158.119.147.40 at 2011-03-28 15:00:15) [GET]
  [4;36;1mUser Load (1.6ms)[0m   [0;1mSELECT * FROM "users" WHERE ("users"."id" = 1) LIMIT 1[0m
  [4;35;1mRole Load (0.9ms)[0m   [0mSELECT "roles".* FROM "roles" INNER JOIN "roles_users" ON "roles".id = "roles_users".role_id WHERE ("roles"."name" = E'admin') AND ("roles_users".user_id = 1 ) LIMIT 1[0m
Rendering template within layouts/registrations
Rendering users/registrations/new
  [4;36;1mRole Load (0.3ms)[0m   [0;1mSELECT * FROM "roles" [0m
  [4;35;1mCACHE (0.0ms)[0m   [0mSELECT "roles".* FROM "roles" INNER JOIN "roles_users" ON "roles".id = "roles_users".role_id WHERE ("roles"."name" = E'admin') AND ("roles_users".user_id = 1 ) LIMIT 1[0m
Rendered shards/_login_bar (2.6ms)
Rendered shards/_header (3.5ms)
Rendered shards/_menu (1.4ms)
Completed in 66ms (View: 21, DB: 3) | 200 OK [http://158.119.147.40/efoss/users/registrations]
  [4;36;1mSQL (0.2ms)[0m   [0;1mSET client_min_messages TO 'panic'[0m
  [4;35;1mSQL (0.2ms)[0m   [0mSET client_min_messages TO 'notice'[0m


Processing RegistrationsController#create (for 158.119.147.40 at 2011-03-28 15:00:35) [POST]
  Parameters: {"user"=>{"roles"=>"1", "password_confirmation"=>"zomgapsw0rd", "lname"=>"Ee", "fname"=>"Mr", "password"=>"zomgapsw0rd", "email"=>"mree@notanemail.com"}, "commit"=>"Sign up", "authenticity_token"=>"AViEsObUf5Dadeb0pygJ5BoO8YS9EyURW0vJeBDHiRw="}
  [4;36;1mUser Load (1.7ms)[0m   [0;1mSELECT * FROM "users" WHERE ("users"."id" = 1) LIMIT 1[0m
Redirected to http://158.119.147.40/efoss/
Filter chain halted as [:require_no_authentication] rendered_or_redirected.

config/routes.rb

      map.devise_for :users

      map.new_user_registration 'users/registrations', :controller => 'users/registrations', :action => 'new'
      #map.connect 'users/registrations', :controller => 'users/registrations', :action => 'create', :conditions => {:method => :post}

controllers/users/registrations_controller.rb

class Users::RegistrationsController < Devise::RegistrationsController
  #prepend_before_filter :require_no_authentication, :only => [ :new, :create ]
  skip_before_filter :require_no_authentication
  prepend_before_filter :authenticate_scope!, :only => [:edit, :update, :destroy]
  include Devise::Controllers::InternalHelpers

  #before_filter :check_permissions, :only => [:new, :create, :cancel]


  # GET /resource/sign_up
  def new
    build_resource
    render_with_scope :new
  end

  # POST /resource
  def create
    build_resource

    if resource.save
      set_flash_message :notice, :signed_up
      sign_in_and_redirect(resource_name, resource)
    else
      render_with_scope :new
    end
  end

  # GET /resource/edit
  def edit
    render_with_scope :edit
  end

  # PUT /resource
  def update
    if self.resource.update_with_password(params[resource_name])
      set_flash_message :notice, :updated
      redirect_to after_sign_in_path_for(self.resource)
    else
      render_with_scope :edit
    end
  end

  # DELETE /resource
  def destroy
    self.resource.destroy
    set_flash_message :notice, :destroyed
    sign_out_and_redirect(self.resource)
  end

  def check_permissions
    authorize! :create, resource
  end
end

views/users/registrations/new.html.erb

    <h2>Sign up</h2>

<% form_for @user do |f| -%>
  <%= f.error_messages %>
  <p><%= f.label :email %></p>
  <p><%= f.text_field :email %></p>

  <p><%= f.label :fname, "First name" %></p>
  <p><%= f.text_field :fname %></p>

  <p><%= f.label :lname, "Last name" %></p>
  <p><%= f.text_field :lname %></p>

  <p><%= f.label :roles %></p>
  <p><%= f.select :roles, Role.all.collect{|r| [r.name, r.id]} %></p>

  <p><%= f.label :password %></p>
  <p><%= f.password_field :password, {:class => "password_check"} %></p>

  <p><%= f.label :password_confirmation %></p>
  <p><%= f.password_field :password_confirmation, {:class => "password_check"} %></p>

  <p><%= f.submit "Sign up" %></p>
<% end -%>
  • 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-20T23:33:44+00:00Added an answer on May 20, 2026 at 11:33 pm

    In the end I ended up defining the url to submit the form to in the form itself – not ideal and uses abit of a hack – if anyone can suggest a cleaner way of doing this I’ll save the tick for that answer;

    routes.rb

        map.devise_for :users
      map.new_user_registration '/users/registrations/new', :controller => 'users/registrations', :action => 'new', :conditions => {:method => :get}
      map.create_user_registration '/users/registrations/create', :controller => 'users/registrations', :action => 'create', :conditions => {:method => :post}
    

    views/users/registrations/new.html.erb

        <h2>Sign up</h2>
    
    <% form_for @user, :url => '../../users/registrations/create' do |f| -%>
      <%= f.error_messages %>
      <p><%= f.label :email %></p>
      <p><%= f.text_field :email %></p>
    
      <p><%= f.label :fname, "First name" %></p>
      <p><%= f.text_field :fname %></p>
    
      <p><%= f.label :lname, "Last name" %></p>
      <p><%= f.text_field :lname %></p>
    
      <p><%= f.label :roles %></p>
      <p><%= f.select :roles, Role.all.collect{|r| [r.name, r.id]} %></p>
    
      <p><%= f.label :password %></p>
      <p><%= f.password_field :password, {:class => "password_check"} %></p>
    
      <p><%= f.label :password_confirmation %></p>
      <p><%= f.password_field :password_confirmation, {:class => "password_check"} %></p>
    
      <p><%= f.submit "Sign up" %></p>
    <% end -%>
    

    ugly hack with ‘../../users/registrations’ otherwise the form is routed to ‘users/registrations/users/registrations’ – if the :url modifier is left out then the form is submitted to the default Devise registrations controller action ‘create’ not ‘Users/Registrations’

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using rails 2.3.5 and devise 1.0.6. I'm having users confirm account's with email.
I've got a very simple Rails 3 app with a User model run by
I have a Rails application for which I use devise to authenticate my users
I'm just starting out with Ruby and Rails, trying out Devise with Rails 3.
I use Ruby On Rails and devise gem. I want redirect user after registration,
in rails 3 devise, a user record has an encrypted_password and a password_salt. How
I have Devise setup on a Rails Model: devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable
I am using Devise in my Ruby on Rails 3 application. I am trying
I'm trying to use the Mongoid / Devise Rails 3.1 template ( Mongoid and
My rails 3 app uses devise, and we have it set so a user

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.