使用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