Rails Devise注册表单不接受自定义用户名字段 [英] Rails Devise signup form not accepting custom username field

查看:125
本文介绍了Rails Devise注册表单不接受自定义用户名字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to add a username to my devise installation, ala the Railscast episode. I've added the field to my user model, but when I attempt to create a new user with a username, the form action keeps trying to pass a null value to my database, which raises an error.

这是我的用户模型的模式:

Here's the schema for my User model:

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

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

And here's the hash that gets passed via my sign up form:

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

但是,如上所述,这是一个错误。特别是因为它尝试在表中插入NULL,即使POST散列包含用户名的值。

But, this is throwing an error, as mentioned above. Specifically because it's attempting to insert NULL into the table, even though the POST hash includes a value for username.

任何帮助都不胜感激。

推荐答案

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

Are you sure username is in your attr_accessible list?

这篇关于Rails Devise注册表单不接受自定义用户名字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆