Note that there are some explanatory texts on larger screens.

plurals
  1. PORails: (Devise) Two different methods for new users?
    primarykey
    data
    text
    <p>I have a Rails 3 app with authentication setup using <a href="https://github.com/plataformatec/devise" rel="noreferrer">Devise</a> with the <code>registerable</code> module enabled.</p> <p>I want to have new users who sign up using our outside register form to use the full Devise <code>registerable</code> module, which is happening now.</p> <p>However, I also want the <code>admin</code> user to be able to create new users directly, bypassing (I think) Devise's <code>registerable</code> module.</p> <ul> <li><p>With <code>registerable</code> disabled, my standard UsersController works as I want it to for the <code>admin</code> user, just like any other Rail scaffold. However, now new users can't register on their own.</p></li> <li><p>With <code>registerable</code> enabled, my standard UsersController is never called for the new user action (calling <code>Devise::RegistrationsController</code> instead), and my CRUD actions don't seem to work at all (I get dumped back onto my root page with no new user created and no flash message). Here's the log from the request:</p> <pre><code>Started POST "/users" for 127.0.0.1 at 2010-12-20 11:49:31 -0500 Processing by Devise::RegistrationsController#create as HTML Parameters: {"utf8"=&gt;"✓", "authenticity_token"=&gt;"18697r4syNNWHfMTkDCwcDYphjos+68rPFsaYKVjo8Y=", "user"=&gt;{"email"=&gt;"test@test.com", "password"=&gt;"[FILTERED]", "password_confirmation"=&gt;"[FILTERED]", "role"=&gt;"manager"}, "commit"=&gt;"Create User"} SQL (0.9ms) ... User Load (0.6ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 2) LIMIT 1 SQL (0.9ms) ... Redirected to http://test-app.local/ Completed 302 Found in 192ms </code></pre></li> </ul> <p>... but I am able to register new users through the outside form.</p> <p>How can I get both of these methods to work together, such that my <code>admin</code> user can manually create new users <strong><em>and</em></strong> guest users can register on their own?</p> <hr> <p>I have my Users controller setup for standard CRUD:</p> <pre><code>class UsersController &lt; ApplicationController load_and_authorize_resource def index @users = User.where("id NOT IN (?)", current_user.id) # don't display the current user in the users list; go to account management to edit current user details end def new @user = User.new end def create @user = User.new(params[:user]) if @user.save flash[:notice] = "#{ @user.email } created." redirect_to users_path else render :action =&gt; 'new' end end def edit end def update params[:user].delete(:password) if params[:user][:password].blank? params[:user].delete(:password_confirmation) if params[:user][:password].blank? and params[:user][:password_confirmation].blank? if @user.update_attributes(params[:user]) flash[:notice] = "Successfully updated User." redirect_to users_path else render :action =&gt; 'edit' end end def delete end def destroy redirect_to users_path and return if params[:cancel] if @user.destroy flash[:notice] = "#{ @user.email } deleted." redirect_to users_path end end end </code></pre> <p>And my routes setup as follows:</p> <pre><code>TestApp::Application.routes.draw do devise_for :users devise_scope :user do get "/login", :to =&gt; "devise/sessions#new", :as =&gt; :new_user_session get "/logout", :to =&gt; "devise/sessions#destroy", :as =&gt; :destroy_user_session end resources :users do get :delete, :on =&gt; :member end authenticate :user do root :to =&gt; "application#index" end root :to =&gt; "devise/session#new" end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload