title: Rails - Devise / User registration route / POST
body: <p>I'm stuck a bit with the following problem: I use Devise in Rails, when I open the sign up form and submit it with new the data for the new user, no new user is created in the sqlite-db. I think it's because the POST-route for /register is not properly set:</p>
  
  <pre><code>rake routes:
                      root        /                         static#home
          new_user_session GET    /login(.:format)          devise/sessions#new
              user_session POST   /login(.:format)          devise/sessions#create
      destroy_user_session DELETE /logout(.:format)         devise/sessions#destroy
             user_password POST   /password(.:format)       devise/passwords#create
         new_user_password GET    /password/new(.:format)   devise/passwords#new
        edit_user_password GET    /password/edit(.:format)  devise/passwords#edit
                           PUT    /password(.:format)       devise/passwords#update
  cancel_user_registration GET    /cancel(.:format)         devise/registrations#cancel
         user_registration POST   /                         devise/registrations#create
     new_user_registration GET    /register(.:format)       devise/registrations#new
    edit_user_registration GET    /edit(.:format)           devise/registrations#edit
                           PUT    /                         devise/registrations#update
                           DELETE /                         devise/registrations#destroy
                     users GET    /users(.:format)          users#index
                           POST   /users(.:format)          users#create
                  new_user GET    /users/new(.:format)      users#new
                 edit_user GET    /users/:id/edit(.:format) users#edit
                      user GET    /users/:id(.:format)      users#show
                           PUT    /users/:id(.:format)      users#update
                           DELETE /users/:id(.:format)      users#destroy
  </code></pre>
  
  <p>How should I update routes.rb, maybe only :path_names with adding POST for register in some way?:</p>
  
  <pre><code>root to: 'static#home'
  devise_for :users, :path =&gt; '', :path_names =&gt; { :sign_in =&gt; "login", :sign_out =&gt; "logout", :sign_up =&gt; "register" }
  </code></pre>
  
  <p>RegistrationsController in Devise(from the devise-homepage, just the default one):</p>
  
  <pre><code>class Devise::RegistrationsController &lt; DeviseController
    prepend_before_filter :require_no_authentication, :only =&gt; [ :new, :create, :cancel ]
    prepend_before_filter :authenticate_scope!, :only =&gt; [:edit, :update, :destroy]
  
    # GET /resource/sign_up
    def new
      build_resource({})
      respond_with self.resource
    end
  
    # POST /resource
    def create
      build_resource(sign_up_params)
  
      if resource.save
        yield resource if block_given?
        if resource.active_for_authentication?
          set_flash_message :notice, :signed_up if is_flashing_format?
          sign_up(resource_name, resource)
          respond_with resource, :location =&gt; after_sign_up_path_for(resource)
        else
          set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
          expire_data_after_sign_in!
          respond_with resource, :location =&gt; after_inactive_sign_up_path_for(resource)
        end
      else
        clean_up_passwords resource
        respond_with resource
      end
    end
  
    # GET /resource/edit
    def edit
      render :edit
    end
  
    # PUT /resource
    # We need to use a copy of the resource because we don't want to change
    # the current user in place.
    def update
      self.resource = resource_class.to_adapter.get!(send(:"current_#{resource_name}").to_key)
      prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)
  
      if update_resource(resource, account_update_params)
        yield resource if block_given?
        if is_flashing_format?
          flash_key = update_needs_confirmation?(resource, prev_unconfirmed_email) ?
            :update_needs_confirmation : :updated
          set_flash_message :notice, flash_key
        end
        sign_in resource_name, resource, :bypass =&gt; true
        respond_with resource, :location =&gt; after_update_path_for(resource)
      else
        clean_up_passwords resource
        respond_with resource
      end
    end
  
    # DELETE /resource
    def destroy
      resource.destroy
      Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)
      set_flash_message :notice, :destroyed if is_flashing_format?
      yield resource if block_given?
      respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name) }
    end
  
    # GET /resource/cancel
    # Forces the session data which is usually expired after sign
    # in to be expired now. This is useful if the user wants to
    # cancel oauth signing in/up in the middle of the process,
    # removing all OAuth session data.
    def cancel
      expire_data_after_sign_in!
      redirect_to new_registration_path(resource_name)
    end
  
    protected
  
    def update_needs_confirmation?(resource, previous)
      resource.respond_to?(:pending_reconfirmation?) &amp;&amp;
        resource.pending_reconfirmation? &amp;&amp;
        previous != resource.unconfirmed_email
    end
  
    # By default we want to require a password checks on update.
    # You can overwrite this method in your own RegistrationsController.
    def update_resource(resource, params)
      resource.update_with_password(params)
    end
  
    # Build a devise resource passing in the session. Useful to move
    # temporary session data to the newly created user.
    def build_resource(hash=nil)
      self.resource = resource_class.new_with_session(hash || {}, session)
    end
  
    # Signs in a user on sign up. You can overwrite this method in your own
    # RegistrationsController.
    def sign_up(resource_name, resource)
      sign_in(resource_name, resource)
    end
  
    # The path used after sign up. You need to overwrite this method
    # in your own RegistrationsController.
    def after_sign_up_path_for(resource)
      after_sign_in_path_for(resource)
    end
  
    # The path used after sign up for inactive accounts. You need to overwrite
    # this method in your own RegistrationsController.
    def after_inactive_sign_up_path_for(resource)
      respond_to?(:root_path) ? root_path : "/"
    end
  
    # The default url to be used after updating a resource. You need to overwrite
    # this method in your own RegistrationsController.
    def after_update_path_for(resource)
      signed_in_root_path(resource)
    end
  
    # Authenticates the current scope and gets the current resource from the session.
    def authenticate_scope!
      send(:"authenticate_#{resource_name}!", :force =&gt; true)
      self.resource = send(:"current_#{resource_name}")
    end
  
    def sign_up_params
      devise_parameter_sanitizer.sanitize(:sign_up)
    end
  
    def account_update_params
      devise_parameter_sanitizer.sanitize(:account_update)
    end
  end
  </code></pre>
  
  <p>new.erb.html:</p>
  
  <pre><code>&lt;h2&gt;Sign up&lt;/h2&gt;
  
  &lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f| %&gt;
    &lt;%= devise_error_messages! %&gt;
  
    &lt;div&gt;&lt;%= f.label :email %&gt;&lt;br /&gt;
    &lt;%= f.email_field :email, :autofocus =&gt; true %&gt;&lt;/div&gt;
  
    &lt;div&gt;&lt;%= f.label :password %&gt;&lt;br /&gt;
    &lt;%= f.password_field :password %&gt;&lt;/div&gt;
  
    &lt;div&gt;&lt;%= f.label :password_confirmation %&gt;&lt;br /&gt;
    &lt;%= f.password_field :password_confirmation %&gt;&lt;/div&gt;
  
    &lt;div&gt;&lt;%= f.submit "Sign up" %&gt;&lt;/div&gt;
  &lt;% end %&gt;
  
  &lt;%= render "devise/shared/links" %&gt;
  </code></pre>