我正在努力找出一个设计问题而我无法弄明白。
我在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_user_registration方法都不会路由到我的新控制器,而是路由到原始的Devise控制器,对create函数的请求将转到我的重写函数。 (即当我使用rails -s --debug
启动服务器时,在执行RegistrationsController#update时永远不会调用调试器。
日志输出如下。请注意,新的#create方法中的logger语句存在,但调试器不是:
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
更新:我意识到我没有解释真正的怪异。解释说有些东西传递给原始控制器而其他东西没有。
有人对我在这里做错了什么有任何想法吗?