link_to更新Devise用户,method =>放

时间:2013-01-31 09:20:58

标签: ruby-on-rails-3 devise put

我正在尝试更新current_user(设计)的单个数据库字段。

我想使用link_to helper:

来做到这一点
<%= link_to "Grid", edit_user_registration_path(current_user, :project_view => "grid"), :method => :put %>

但我无法让它发挥作用,因为结果总是出错:

Routing Error

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

我的设计路线:

        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

路由有什么问题?我正在使用设计,没有任何自定义修改。

谢谢!

1 个答案:

答案 0 :(得分:1)

错误的路径助手:

$ 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

结果:

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

更新您的特定路线:

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