0

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

我只想使用 link_to 助手来做到这一点:

<%= 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

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

谢谢!

4

1 回答 1

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?" %>
于 2013-01-31T12:04:42.300 回答