【问题标题】:Devise Update method does not have ID in route设计更新方法在路由中没有 ID
【发布时间】:2014-06-11 15:22:26
【问题描述】:

我有两个使用 Devise 3 的模型。我的编辑和更新路线没有我期望的 /:id,这导致我收到错误的 PUT 请求,如下所示。

Started PUT "/users.user" for 127.0.0.1 at 2014-06-11 11:11:46 -0400
Processing by RegistrationsController#update as 

Completed 406 Not Acceptable in 4894.6ms (ActiveRecord: 2.4ms)

这里是路线

               new_user_session GET        /users/sign_in(.:format)                           sessions#new
                   user_session POST       /users/sign_in(.:format)                           sessions#create
           destroy_user_session DELETE     /users/sign_out(.:format)                          sessions#destroy
                  user_password POST       /users/password(.:format)                          passwords#create
              new_user_password GET        /users/password/new(.:format)                      passwords#new
             edit_user_password GET        /users/password/edit(.:format)                     passwords#edit
                                PUT        /users/password(.:format)                          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

这就是我的 routes.rb 的样子

  devise_for :users, :controllers => { :confirmations => "confirmations", registrations: "registrations", session: "sessions", passwords: "passwords" } 

  devise_scope :user do
    authenticated :user do
      root :to => 'appointments#index', as: :user_authenticated_root
      get "/appointments", to: "appointments#index", as: :appointments
    end
    unauthenticated :user do
      root :to => 'devise/registrations#new', as: :unauthenticated_root
    end   
    match '/join' => 'devise/registrations#new'
  end

我的表格是

<%= simple_form_for(resource, :as => resource_name, :url => user_registration_path(resource_name)) do |f| %>
  <%= f.error_notification %>

我缺少什么来修复说 /users/:id(.:format) 等的路由?

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 devise routes updates


    【解决方案1】:

    我认为应该这样做:

    <%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>
    

    【讨论】:

      猜你喜欢
      • 2011-10-22
      • 1970-01-01
      • 2011-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-27
      • 1970-01-01
      相关资源
      最近更新 更多