1

I'm trying to update a single databasefield of my current_user (devise).

I want to do this just with the link_to helper:

<%= link_to "Grid", edit_user_registration_path(current_user, :project_view => "grid"), :method => :put %>

But I can't get it to work since the result it allways an error:

Routing Error

No route matches [PUT] "/users/edit.1"

My Routes for Devise:

        new_user_session GET    /users/sign_in(.:format)       devise/sessions#new
            user_session POST   /users/sign_in(.:format)       devise/sessions#create
    destroy_user_session DELETE /users/sign_out(.:format)      devise/sessions#destroy
           user_password POST   /users/password(.:format)      devise/passwords#create
       new_user_password GET    /users/password/new(.:format)  devise/passwords#new
      edit_user_password GET    /users/password/edit(.:format) devise/passwords#edit
                         PUT    /users/password(.:format)      devise/passwords#update
cancel_user_registration GET    /users/cancel(.:format)        devise/registrations#cancel
       user_registration POST   /users(.:format)               devise/registrations#create
   new_user_registration GET    /users/sign_up(.:format)       devise/registrations#new
  edit_user_registration GET    /users/edit(.:format)          devise/registrations#edit
                         PUT    /users(.:format)               devise/registrations#update
                         DELETE /users(.:format)               devise/registrations#destroy

What's wrong with the routing? I'm using devise without any custom modifications.

Thanks!

Andre Zimpel
  • 2,323
  • 4
  • 27
  • 42

1 Answers1

1

Wrong path helper:

$ rake routes
 new_user_registration    GET     ...  registrations#new
 cancel_user_registration GET     ...  registrations#cancel
 user_registration        POST    ...  registrations#create
 edit_user_registration   GET     ...  registrations#edit
             users        PUT     ...  registrations#update # You want this one
                          DELETE  ...  registrations#destroy

Result:

<%= link_to "Grid", users_path(:user => {:project_view => 'grid'}), :method => :put, :confirm => "Are you sure?" %>

Update for your specific routes:

<%= link_to "Grid", registration_path(resource_name, :user => {:project_view => 'grid'}), :method => :put, :confirm => "Are you sure?" %>
jibiel
  • 8,175
  • 7
  • 51
  • 74
  • Thank you! Using your solution ends up in an error: `undefined method "users_path" for #<#:0x007f9a54ceeb90>` I don't even have the `users` in front of the put for the update action :/ – Andre Zimpel Jan 31 '13 at 12:16
  • but this still takes me back to /users/edit.id page where I have to fill in the password. Could a custom action be a better solution? Or is there an easy way to shwitch off the password confirmation in devise - without editing the RegistrationsController itself? – Andre Zimpel Jan 31 '13 at 13:04
  • Just to make sure it works you can pass the password in the attributes `:user => {:project_view => 'grid', :current_password => '...'}` (development only, of course). As to Devise configuration — this is another question. I'd split user data to «sensitive» (requires password to update) and «profile». So yeah, this may end up in custom action. – jibiel Jan 31 '13 at 13:16
  • Thanks for yout help! Nice idea. I'm going to create a profile model – Andre Zimpel Jan 31 '13 at 13:45