Rails设计注册表单不接受自定义用户名字段

时间:2010-10-17 15:44:12

标签: ruby-on-rails devise

我正在尝试为我的设计安装添加一个用户名,这是Railscast的一集。我已将该字段添加到我的用户模型中,但是当我尝试使用用户名创建新用户时,表单操作会不断尝试将空值传递给我的数据库,这会引发错误。

以下是我的用户模型的架构:

create_table "users", :force => true do |t|
  t.string   "username",                                               :null => false
  t.string   "email",                               :default => "",    :null => false
  t.string   "encrypted_password",   :limit => 128, :default => "",    :null => false
  t.string   "password_salt",                       :default => "",    :null => false
  t.string   "reset_password_token"
  t.string   "remember_token"
  t.datetime "remember_created_at"
  t.integer  "sign_in_count",                       :default => 0
  t.datetime "current_sign_in_at"
  t.datetime "last_sign_in_at"
  t.string   "current_sign_in_ip"
  t.string   "last_sign_in_ip"
  t.datetime "created_at"
  t.datetime "updated_at"
end

这是通过我的注册表单传递的哈希:

{"utf8"=>"✓",
  "authenticity_token"=>"/6Mf3mAd4TQ8uqJ4nPZAu/HbPnktKFmJ+G76j2pUV7U=",
  "user"=>{"email"=>"email@email.co",
  "username"=>"test",
  "password"=>"[FILTERED]",
  "password_confirmation"=>"[FILTERED]"},
  "commit"=>"Sign up"}

但是,如上所述,这会引发错误。特别是因为它试图在表中插入NULL,即使POST哈希包含用户名的值。

感谢任何帮助。

1 个答案:

答案 0 :(得分:4)

您确定用户名在您的attr_accessible列表中吗?

相关问题