views:

65

answers:

1

Hello all,

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 protected]",
  "username"=>"test",
  "password"=>"[FILTERED]",
  "password_confirmation"=>"[FILTERED]"},
  "commit"=>"Sign up"}

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.

Any help is appreciated.

+1  A: 

Are you sure username is in your attr_accessible list?

José Valim
That was it! Out of curiosity, what is the reason that the field needs to be added to attr_accessible?
Kevin Whitaker
@Kevin Whitaker, the Devise readme states : "Devise doesn’t use attr_accessible or attr_protected inside its modules, so be sure to define attributes as accessible or protected in your model."
Zabba