DDDD
DDDD

Reputation: 3940

Password digest can't be blank

Ruby on Rails 3.2

My form is creating a new distributor. I have added the gem 'bcrypt-ruby', '3.0.1', my database table has password_digest: string and my model has :password, :password_confirmation, and has_secure_password.

When I submit my form the error I get is Password digest can't be blank.

This is what is POSTed:

Started POST "/distributors" for x.x.x.x at 2014-03-14 12:59:07 -0700
Processing by DistributorsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"x=", "distributor"=>{"company_name"=>"First Account", "company_website
"=>"First.com", "contact_name"=>"First", "contact_email"=>"[email protected]", "contact_title"=>"owner", "company_phone"=>"555-665-5555", "company_region"=>"Asia Paci
fic", "company_address"=>"172 E Center Street", "company_country"=>"Cambodia", "company_city"=>"Covina", "company_state"=>"Not Applicable", "company_zip"=>"01970",
"sales_contact_name"=>"Bob", "sales_contact_email"=>"[email protected]", "tech_contact_name"=>"Steph", "tech_contact_email"=>"[email protected]", "additional_name"=>"",
"additional_email"=>"", "additional_name2"=>"", "additional_email2"=>"", "area_served"=>["", "Bangladesh"], "terms_and_conditions"=>"1"}, "commit"=>"Register"}
Distributor Load (0.1ms)  SELECT `distributors`.* FROM `distributors` WHERE `distributors`.`contact_email` = '[email protected]' LIMIT 1
(0.1ms)  BEGIN
Distributor Exists (0.2ms)  SELECT 1 AS one FROM `distributors` WHERE `distributors`.`contact_email` = '[email protected]' LIMIT 1
(0.1ms)  ROLLBACK

Does someone know what I'm missing? Thank you

Upvotes: 0

Views: 932

Answers (2)

spickermann
spickermann

Reputation: 106862

The hash you post to your distributors route does not contain any information about a password. It is not possible to create a distributor without a password, with the code you have written. So the error message is perfectly correct.

You need to add a password and a password_confirmation field to your webpage.

Upvotes: 1

Reck
Reck

Reputation: 8782

Your log is missing both the password and password_confirmation fields being set. It should look more like this

{"utf8"=>"✓", "authenticity_token"=>"dsdfhjdskhfsdfhjsdfhjsdfhjdsfhjsdfE=", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Register"}

Upvotes: 1

Related Questions