我正在尝试创建一个简单的用户和地址模型。
我创建了一个嵌套表单,其中包含一个嵌套在 User 模型中的地址模型。我的用户模型具有设计属性等。
一切正常,除了创建用户时发生了奇怪的行为。
如果您阅读下面的内容,您会注意到首次提交记录时填充了拥有用户的地址的“user_id”。但是紧接着,看起来像是在 Devise 核心中的东西,正在将 user_id 重置为 null。
有谁知道这是什么原因造成的?
在 2012-11-03 22:45:20 +1100 开始 POST "/users" for 127.0.0.1 由 Member::UsersController#create as HTML 参数处理:{"utf8"=>"✓", "authenticity_token"=> "Pr8lSEJalWwosuaLPOrYqQ+sOkFCyoNujaUybxpZDAg=", "user"=>{"address_attributes"=>{"first_name"=>"HOlley", "last_name"=>"Hou"}, "email"=>"HollyHou@hisense.com。 au", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}} 创建新用户 (0.1ms) BEGIN (0.1ms) COMMIT (0.0ms) BEGIN Member::User Exists (0.3 毫秒)从
member_users
WHERE中选择 1 作为一个member_users
。member_users
created_at
current_sign_in_at
current_sign_in_ip
encrypted_password
last_sign_in_at
last_sign_in_ip
remember_created_at
reset_password_sent_at
reset_password_token
sign_in_count
,updated_at
) 值 ('2012-11-03 11:45:20', NULL, NULL, 'hollyhou@hisense.com.au', '$2a$10$1JvC/sO85L2esNp8xA9qseTc78.rtOyF3zSBi/fOTiWJRt9.zgYha', NULL, NULL , NULL, NULL, NULL, 0, '2012-11-03 11:45:20') SQL (0.2ms) INSERT INTOmember_addresses
(address3
,address_1
,address_2
,address_type
,business_name
,city
,country
,created_at
,first_name
,geo_late
,geo_long
,is_primary
,last_name
,middle_name
,phone1
,phone1_type
,phone2
,phone2_type
,postcode
,primary_email
,secondary_email
,state
,status
,suburb
,title
,updated_at
,user_id
)值(NULL,NULL,NULL,NULL,NULL,NULL,NULL,'2012-11-03 11:45:20','Holley',NULL,NULL,NULL,'侯',NULL,NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, '2012-11-03 11:45:20', 5) (1.3ms) COMMIT
(0.1ms) BEGIN (0.2ms) UPDATEmember_users
SETlast_sign_in_at
= '2012-11-03 11:45:20',current_sign_in_at
= '2012-11-03 11:45:20',last_sign_in_ip
= '127.0.0.1',current_sign_in_ip
= '127.0.0.1',sign_in_count
= 1,updated_at
= '2012-11- 03 11:45:20' 在哪里member_users
。id
= 5 (0.2ms) COMMIT (0.1ms) BEGIN
(0.2ms) UPDATEmember_addresses
SETuser_id
= NULL,updated_at
= '2012-11-03 11:45:20' WHEREmember_addresses
。id
= 5 (0.2ms) 提交
控制器是一个自定义控制器,因为我最终(一旦我得到这个工作),需要能够在注册后重定向到 2 个不同的地方,这取决于客户从哪里登录(在这种情况下是结帐或标题)。
class Member::UsersController < Devise::RegistrationsController
def create
super
end
def new
super
end
def edit
Rails.logger.debug { "Editing the user" }
super
end
def show
Rails.logger.debug { "Showing the user controller" }
end
end
并来自 routes.rb
devise_for :users, :class_name => "Member::User", :controllers => {:registrations => 'member/users', :sessions => 'member/sessions'}