Create new user in the database via Rails C

Asked

Viewed 151 times

1

Help me where the error is occurring, because I am not able to identify pq the field is not being recognized.

Rails c

u = User.new(email:'[email protected]', registration:192536, password:'changeme', password_confirmation:'changeme')

Look at the error

irb(main):002:0> u.save
   (0.4ms)  BEGIN
  User Exists (1.6ms)  SELECT  1 AS one FROM "users" WHERE "users"."email" = $1 LIMIT $2  [["email", "[email protected]"], ["LIMIT", 1]]
  SQL (1.5ms)  INSERT INTO "users" ("email", "encrypted_password") VALUES ($1, $2) RETURNING "id"  [["email", "[email protected]"], ["encrypted_password", "$2a$11$JieDv.rvWuKi0/34/hooLepn/aKb1a.ZJrlL04m2kJCXFjI3b2JOy"]]
   (0.3ms)  ROLLBACK
ActiveRecord::StatementInvalid: PG::NotNullViolation: ERROR:  null value in column "registration" violates not-null constraint
DETAIL:  Failing row contains (13, [email protected], null, $2a$11$JieDv.rvWuKi0/34/hooLepn/aKb1a.ZJrlL04m2kJCXFjI3b2JOy, null, null, null, 0, null, null, null, null).
: INSERT INTO "users" ("email", "encrypted_password") VALUES ($1, $2) RETURNING "id"

He doesn’t recognize all the parameters I’m passing, anyone has any idea what it might be ?

  • Try checking with u.Valid? and look at u.errors. errors Can help.

  • 1

    This looks like it lacks an 'attr_accessor' in the model or something else that is preventing mass-assignement in User.new. Which version of Rails is being used?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.