0

I am trying to set-up a two step signup process using Devise in Rails and followed this tutorial by Claudio Marai. When I enter the e-mail address in the form (first step), I get an error telling me there was a routing error and that it couldn't find RegistrationsController

Started POST "/users" for 127.0.0.1 at 2012-05-03 22:50:59 -0400

ActionController::RoutingError (uninitialized constant RegistrationsController):
  activesupport (3.2.1) lib/active_support/inflector/methods.rb:229:in `block in constantize'
  activesupport (3.2.1) lib/active_support/inflector/methods.rb:228:in `each'
  activesupport (3.2.1) lib/active_support/inflector/methods.rb:228:in `constantize'
  .
  .
  .

I figured this was due to the presence of :registrations => "registrations" in my routes.rb file as described in the first step of the tutorial. I then tried two alternatives which both resulted in the same error. First, I removed the :registrations => "registrations" from the routes.rb file. When that didn't work, I re-inserted the line and added a registrations_controller.rb to the controllers directory which looked like this:

class RegistrationsController < Devise::RegistrationsController
end

I figured the two options would have the same effect - but - I tried them anyway.

The error I got was the following:

Started POST "/users" for 127.0.0.1 at 2012-05-03 22:47:29 -0400
Processing by Devise::RegistrationsController#create as HTML
  Parameters: {"utf8"=>"?", "authenticity_token"=>"ttPBRPRLVzPBHcDDKRJbimv0Yp/egdK5qBkIvBTL4Ig=", "user"=>{"email"=>"test@email.com"}, "x"=>"0", "y"=>"0"}
   (0.6ms)  begin transaction
  User Exists (1.5ms)  SELECT 1 FROM "users" WHERE "users"."email" = 'test@email.com' LIMIT 1
  CACHE (0.0ms)  SELECT 1 FROM "users" WHERE "users"."email" = 'test@email.com' LIMIT 1
  User Load (0.6ms)  SELECT "users".* FROM "users" WHERE "users"."confirmation_token" = '8tA1jakpAXNK4Piz7J6R' LIMIT 1
  SQL (14.0ms)  INSERT INTO "users" ("confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "fb_id", "fb_token", "first_name", "last_name", "last_sign_in_at", "last_sign_in_ip", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "state", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)  [["confirmation_sent_at", Thu, 03 May 2012 22:47:30 EDT -04:00], ["confirmation_token", "8tA1jakpAXNK4Piz7J6R"], ["confirmed_at", nil], ["created_at", Thu, 03 May 2012 22:47:30 EDT -04:00], ["current_sign_in_at", nil], ["current_sign_in_ip", nil], ["email", "test@email.com"], ["encrypted_password", nil], ["fb_id", nil], ["fb_token", nil], ["first_name", nil], ["last_name", nil], ["last_sign_in_at", nil], ["last_sign_in_ip", nil], ["remember_created_at", nil], ["reset_password_sent_at", nil], ["reset_password_token", nil], ["sign_in_count", 0], ["state", nil], ["updated_at", Thu, 03 May 2012 22:47:30 EDT -04:00]]
SQLite3::ConstraintException: constraint failed: INSERT INTO "users" ("confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "fb_id", "fb_token", "first_name", "last_name", "last_sign_in_at", "last_sign_in_ip", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "state", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
   (0.3ms)  rollback transaction
Completed 500 Internal Server Error in 441ms

ActiveRecord::StatementInvalid (SQLite3::ConstraintException: constraint failed: INSERT INTO "users" ("confirmation_sent_at", "confirmation_token", "confirmed_at", "created_at", "current_sign_in_at", "current_sign_in_ip", "email", "encrypted_password", "fb_id", "fb_token", "first_name", "last_name", "last_sign_in_at", "last_sign_in_ip", "remember_created_at", "reset_password_sent_at", "reset_password_token", "sign_in_count", "state", "updated_at") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)):
  sqlite3 (1.3.5) lib/sqlite3/statement.rb:108:in `step'
  sqlite3 (1.3.5) lib/sqlite3/statement.rb:108:in `block in each'
  sqlite3 (1.3.5) lib/sqlite3/statement.rb:107:in `loop'
  sqlite3 (1.3.5) lib/sqlite3/statement.rb:107:in `each'
  .
  .
  .

The above error has me really confused!

With the same form, when I add the password and password_confirmation fields, then things proceed smoothly - the user account is created and a confirmation email is sent to the user with the confirmation link.

I would appreciate any help regarding this - thanks! I am using Ruby 1.9.3-p125 and Rails 3.2.1

4

1 に答える 1

3

The issue isn't due to Rails validation, it's due to a violation of a database constraint.

More than likely, if your users table migration was generated by Devise, then the schema includes this:

"encrypted_password" varchar(128) DEFAULT '' NOT NULL

The SQL that's causing the ConstraintException includes this (elided for readability):

SQL (14.0ms)  INSERT INTO "users" (..., "encrypted_password", ...) VALUES (..., ?, ...)  [..., ["encrypted_password", nil], ...]

So, something is telling your database adapter to set encrypted_password = nil.

You should be able to circumvent it either be running a migration that removes the NOT NULL constraint on the encrypted_password, or do as you've done, pass in an encrypted_password, but just make sure it's empty in the first step, but present in the second step.

于 2012-05-08T04:07:19.040 に答える