title: Customising Devise registration edit/update routes and views
body: <p>I've just started using Devise and I've made some customisations:</p>
  
  <ul>
  <li>I've generated views and customised my views (signup form etc)</li>
  <li>I've generated controllers so I can make some changes there</li>
  <li>I've customised routes, mostly as per this post: <a href="http://iampedantic.com/post/41170460234/fully-customizing-devise-routes" rel="nofollow">http://iampedantic.com/post/41170460234/fully-customizing-devise-routes</a></li>
  </ul>
  
  <p>Everything works great except the edit_user_registration stuff (the view where users can change their email and password or delete their account).</p>
  
  <p>This is what I have for registrations in <code>config/routes.rb</code> (parts not related to registrations controller are omitted):</p>
  
  <pre><code>devise_for  :users, skip: [:registrations]
  
  as :user do
  
    # joining
    get   '/register' =&gt; 'users/registrations#new', as: 'new_user_registration'
    post  '/register' =&gt; 'users/registrations#create', as: 'user_registration'
  
    scope '/user' do
  
    # settings &amp; cancellation
    get '/cancel'   =&gt; 'users/registrations#cancel', as: 'cancel_user_registration'
    get '/settings' =&gt; 'users/registrations#edit', as: 'edit_user_registration'
    patch '/settings' =&gt; 'users/registrations#update'
  
    # account deletion
    delete '' =&gt; 'users/registrations#destroy'
  
  end
  </code></pre>
  
  <p>I changed <code>put</code> to <code>patch</code> because I'm using Rails 4 (is this correct?).</p>
  
  <p>This is my form_for tag in <code>views/users/registrations/edit.html.erb</code>:</p>
  
  <pre><code>&lt;%= form_for(resource,  as: resource_name,
                              url: registration_path(resource_name),
                              html: { method: :patch }) do |f| %&gt;
  </code></pre>
  
  <p>When I try to update settings for a user with the above code, I get a 500 internal server error. Submitting the form attempts to load <code>/register</code> (my signup page), which is surely not right. <em>(I think this is the heart of the problem but I don't understand how to fix it as I'm quite a beginner.)</em></p>
  
  <p>When I try to update settings for a user with the original <code>put</code> method (instead of <code>patch</code>), I get the same problem.</p>
  
  <p>My development web server says:</p>
  
  <pre><code>ActionController::RoutingError (No route matches [PUT] "/register"):
  </code></pre>
  
  <p>Thanks in advance.</p>
  
  <p>EDIT: Added <code>rake routes</code> output below.</p>
  
  <pre><code>                  Prefix Verb   URI Pattern                     Controller#Action
     new_user_registration GET    /register(.:format)             users/registrations#new
         user_registration POST   /register(.:format)             users/registrations#create
  cancel_user_registration GET    /user/cancel(.:format)          users/registrations#cancel
    edit_user_registration GET    /user/settings(.:format)        users/registrations#edit
                  settings PUT    /user/settings(.:format)        users/registrations#update
                           DELETE /user(.:format)                 users/registrations#destroy
  </code></pre>
  
  <p>EDIT 2: This is what <code>rakes routes</code> looks like when I remove custom routes and let Devise handle registrations views etc.:</p>
  
  <pre><code>                  Prefix Verb   URI Pattern                     Controller#Action
     new_user_registration GET    /users/sign_up(.:format)        devise/registrations#new
         user_registration POST   /users(.:format)                devise/registrations#create
  cancel_user_registration GET    /users/cancel(.:format)         devise/registrations#cancel
    edit_user_registration GET    /users/edit(.:format)           devise/registrations#edit
                           PATCH  /users(.:format)                devise/registrations#update
                           PUT    /users(.:format)                devise/registrations#update
                           DELETE /users(.:format)                devise/registrations#destroy
  </code></pre>
  
  <p>WORKING:</p>
  
  <p><strong>routes.rb</strong>:</p>
  
  <pre><code>get 'settings'  =&gt; 'users/registrations#edit', as: 'edit_user_registration'
  put 'settings/:id' =&gt; 'users/registrations#update', as: 'update_user_registration'
  </code></pre>
  
  <p><strong>edit.html.erb</strong>:</p>
  
  <pre><code>&lt;%= form_for(resource,  as: resource_name,
                          url: update_user_registration_path(resource_name),
                          html: { method: :put }) do |f| %&gt;
  </code></pre>