使用Rails 3.2和Devise,我已经用自定义的覆盖了注册控制器。我根本没有更改create
方法中的代码,它是Devise中的原始代码。电子邮件说是空的不是用Rails 3.2和Devise
但奇怪的是,每当我尝试创建/注册一个新用户时,我总是收到这个错误。
PG::Error: ERROR: null value in column "email" violates not-null constraint
: INSERT INTO "users" ("created_at", "current_sign_in_at", "current_sign_in_ip", "email", "last_sign_in_at", "last_sign_in_ip", "payroll", "sign_in_count", "updated_at", "username") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING "id"
但是在它下面,一切似乎都没问题,因为用户正在收到一封有效的电子邮件。
{"utf8"=>"✓",
"authenticity_token"=>"8/ZKW11lF22WYKV2K36zBkSk6DSU36/1/zU54a2IRmM=",
"user"=>{"username"=>"someguy",
"email"=>"[email protected]",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]"},
"commit"=>"Sign up",
"format"=>"user"}
我不太清楚在这里粘贴什么其他代码,因为所有的东西显然都适合我。所以请请求任何可能有帮助的东西。
这是我的注册控制器,但create
基本上有相同的代码其super
。错误发生在有resource.save
的行。
class UserRegistrationsController < Devise::RegistrationsController
def new
super
end
def create
build_resource
if resource.save
if resource.active_for_authentication?
set_flash_message :notice, :signed_up if is_navigational_format?
sign_up(resource_name, resource)
respond_with resource, :location => after_sign_up_path_for(resource)
else
set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_navigational_format?
expire_session_data_after_sign_in!
respond_with resource, :location => after_inactive_sign_up_path_for(resource)
end
else
clean_up_passwords resource
respond_with resource
end
end
def update
super
end
end
显然,所有的字段都是nil
。这是它执行查询:
INSERT INTO "users" ("created_at", "current_sign_in_at", "current_sign_in_ip", "email", "first_name", "last_name", "last_sign_in_at", "last_sign_in_ip", "payroll", "sign_in_count", "updated_at", "username") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) RETURNING "id" [["created_at", Wed, 17 Apr 2013 19:34:22 BST +01:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["email", nil], ["first_name", nil], ["last_name", nil], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["payroll", nil], ["sign_in_count", 0], ["updated_at", Wed, 17 Apr 2013 19:34:22 BST +01:00], ["username", ""]]
请发布您的'registrations_controller.rb' – benchwarmer
@benchwarmer,我已将它附加到原始帖子。 – cgf
你可以添加'build_resource'方法吗?我假设它在你的超类'RegistrationsController'中? – covard