title: Allow a user to add new users in Devise, and remain logged in as themselves
body: <p>I am using Ruby On Rails with Devise, Rails 4.1.0.rc1, Ruby 2.1.0p0, devise-3.2.4</p>
  
  <p>I followed the tutorial from Rails Cast Episode #209 to get devise installed and working.  I can login and log out and register new users. </p>
  
  <p>I extended my user model to include non-changing information like birthdate, first name and last name. </p>
  
  <p>Following this blog post I added a user controller &amp; views in order to add additional functionality such as a listing of all users that I did not see with devise. 
  <a href="https://github.com/danweller18/devise/wiki/Allow-Users-to-View-Profile-and-List-All-Users" rel="nofollow noreferrer">https://github.com/danweller18/devise/wiki/Allow-Users-to-View-Profile-and-List-All-Users</a></p>
  
  <p>I have also reviewed these questions on Stack overflow:
  <a href="https://stackoverflow.com/questions/19017978/allowing-admins-to-add-users-with-devise">Allowing admins to add users with Devise</a>
  <a href="https://stackoverflow.com/questions/5851801/how-do-i-customize-the-controller-for-registration-in-devise">How do I customize the controller for registration in Devise?</a>
  <a href="https://stackoverflow.com/questions/18394001/ruby-on-rails-custom-devise-registration-controller-asking-for-create-action/18394302#18394302">Ruby on Rails: Custom Devise Registration Controller, Asking For Create Action</a></p>
  
  <p>I am new to ruby on rails since March 1st of this year, and have taken Mike &amp; Nicole Clarks Rails 1 &amp; Rails 2 online courses. </p>
  
  <p>What I am trying to do is allow a user to add new users.  Ultimately this function would be an admin or manager adding clients.   The client should then be able to log in with the credentials created. </p>
  
  <p>What is occurring is that I can be logged in, add a new "user" through the new_user_path and user view (as opposed to the devise view) but when I submit it, I am then logged in as the new user.  The previous users is not persistent. </p>
  
  <p>I am doing all of this via the users view &amp; controller actions because I don't want to actually "register" or login &amp; logout with these actions, just create new records in the user table that would then be able to log in on their own.  </p>
  
  <p>Any help is appreciated. </p>
  
  <p>here is my user controller: </p>
  
  <pre><code>class UsersController &lt; ApplicationController
  
      def index
          @users = User.all
      end
  
      def show
        @user = User.find_by_id(params[:id])
      end
  
      def new
          @user = User.new
      end
  
      def edit
          @user = User.find(params[:id])
      end
  
      def update
          @user = User.find(params[:id])
          if @user.update_attributes(user_params)
              redirect_to user_url, notice: "Updated User."
          else
              render :edit
          end
      end
  
      def create
          @user = User.new(user_params)
          if @user.save
              redirect_to user_url, notice: "User succesfully created!" 
          else
              render :new
          end
      end
  
  
  
  
  
  
  private
  
  def user_params
    params.require(:user).permit(:first_name, :last_name, :img_file_name, :email, :password, :password_confirmation, :birthdate)
  end
  end
  </code></pre>
  
  <p>Here is my application controller: </p>
  
  <pre><code>class ApplicationController &lt; ActionController::Base
    # Prevent CSRF attacks by raising an exception.
    # For APIs, you may want to use :null_session instead.
    protect_from_forgery with: :exception
  
  before_action :configure_permitted_parameters, if: :devise_controller?
  
  
  protected
  
      def configure_permitted_parameters
          devise_parameter_sanitizer.for(:account_update) {|u| 
              u.permit(:first_name, :last_name, :birthdate, :img_file_name, :email, :password, :password_confirmation, :current_password)}
          devise_parameter_sanitizer.for(:sign_up) {|u| 
              u.permit(:first_name, :last_name, :birthdate, :img_file_name, :email, :password, :password_confirmation, :current_password)}
      end
  
  
  
  
  end
  </code></pre>
  
  <p>Here is my user new.html.erb file: (Admins Only is just a reminder for me right now, there is no admin function at them moment)  </p>
  
  <pre><code>&lt;header id="content-header"&gt;
    &lt;h1&gt;Create a New User (Admins Only)&lt;/h1&gt;
  &lt;/header&gt;
  
  &lt;%= render 'form' %&gt;
  </code></pre>
  
  <p>Here is the _form.html.erb</p>
  
  <pre><code>&lt;%= form_for(@user) do |f| %&gt;
    &lt;%= render "shared/errors", object: @user %&gt;
    &lt;fieldset&gt;
      &lt;ol&gt;
  
        &lt;li class="required"&gt;
          &lt;%= f.label :first_name %&gt;
          &lt;%= f.text_field :first_name, size: 40, autofocus: true %&gt;
        &lt;/li&gt;
        &lt;li class="required"&gt;
          &lt;%= f.label :last_name %&gt;
          &lt;%= f.text_field :last_name, size: 40 %&gt;
        &lt;/li&gt;
        &lt;li class="required"&gt;
          &lt;%= f.label :email %&gt;
          &lt;%= f.email_field :email, size: 40 %&gt;
        &lt;/li&gt;
        &lt;li class="required"&gt;
          &lt;%= f.label :password %&gt;
          &lt;%= f.password_field :password, size: 40 %&gt;
        &lt;/li&gt;
        &lt;li class="required"&gt;
          &lt;%= f.label :password_confirmation, "Confirm Password" %&gt;
          &lt;%= f.password_field :password_confirmation, size: 40 %&gt;
        &lt;/li&gt;
        &lt;li &gt;
          &lt;%= f.label :birthdate %&gt;&lt;br/&gt;
          &lt;%= f.date_select :birthdate, start_year: 1915 %&gt;&lt;br/&gt;
        &lt;/li&gt;
  
        &lt;li &gt;
            &lt;%= f.label :img_file_name %&gt;&lt;br/&gt;
            &lt;%= f.text_field :img_file_name %&gt;
        &lt;/li&gt;
  
      &lt;/ol&gt;
      &lt;p&gt;
        &lt;% if @user.new_record? %&gt;
          &lt;%= f.submit "Create Account" %&gt;
        &lt;% else %&gt;
          &lt;%= f.submit "Update Account" %&gt;
        &lt;% end %&gt;
        &lt;%= link_to "Cancel", users_path, class: 'button' %&gt;
      &lt;/p&gt;
    &lt;/fieldset&gt;
  &lt;% end %&gt;
  </code></pre>