我正在解决一个设计问题,但我就是想不通。
我在我的 Registrations 控制器中定义了一个新的更新方法,其开头为:
class RegistrationsController < Devise::RegistrationsController
def update
debugger
@user = session[:registered_as]
logger.info "user: #{@user}"
@user = User.find(current_user.id)
... (lots of other stuff here ) ...
def create
build_resource
logger.debug "I'm creating a new user "
if resource.save
....
我称之为两种形式。一个人发布创建表单(有效),然后我像这样调用更新表单:
<%= simple_form_for(session[:registered_as], :as => resource_name, :url => update_user_registration_path(resource_name), :html => { :method => :put, :class => 'form-vertical' }) do |f| %>
我无法理解的是,无论我做什么,对 create 函数的请求都会转到我的重写函数,而 update_user_registration 方法不会路由到我的新控制器,而是路由到原始的 Devise 控制器。(即,当我使用 启动服务器时rails -s --debug
,执行 RegistrationsController#update 时永远不会调用调试器)。
日志输出如下。请注意,新 #create 方法中的记录器语句在那里,但调试器不存在:
Processing by RegistrationsController#create as */*
Parameters: {"user"=>{"email"=>"adfas@ljljla.com"}}
I'm creating a new user
(0.1ms) begin transaction
....
Reason Load (0.1ms) SELECT "reasons".* FROM "reasons"
Rendered devise/registrations/_thankyou.html.erb (22.2ms)
Completed 200 OK in 45ms (Views: 30.8ms | ActiveRecord: 2.6ms)
Started PUT "/user/registration.user" for 127.0.0.1 at 2013-08-20 18:11:34 -0700
Processing by Devise::RegistrationsController#update as
Parameters: {"utf8"=>"✓", "authenticity_token"=>"0kzemeZYdnDQdV+jQJCE+tvwprPBXKZi/R9wbjsHYds=", "user"=>{"reason_id"=>"1"}, "commit"=>"Record Your Reason"}
Completed 401 Unauthorized in 1ms
路由文件是:
authenticated :user do
root :to => 'home#index'
end
devise_scope :user do
root :to => "devise/registrations#new"
match '/user/registration' => 'devise/registrations#update', :via => :put, :as => :update_user_registration
match '/user/confirmation' => 'confirmations#update', :via => :put, :as => :update_user_confirmation
end
devise_for :users, :controllers => { :registrations => "registrations", :confirmations => "confirmations" }
match 'users/bulk_invite/:quantity' => 'users#bulk_invite', :via => :get, :as => :bulk_invite
resources :users do
get 'invite', :on => :member
end
end
更新:我意识到我没有解释真正的怪异之处。解释了某些东西会传递给原始控制器,而其他东西不会。
有人对我在这里做错了什么有任何想法吗?