Rails 3.2 と Devise を使用して、Registrations Controller をカスタムのものでオーバーライドしました。メソッド内のコードは一切変更しておらずcreate
、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@yahoo.com",
"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", ""]]