I am using Rails 3.2.8 and Devise 2.1.2 (latest) and am baffled as to why I can create a user just fine with Ruby 1.9.2 but not with Ruby 1.9.3, using exactly the same codebase.
Rails console:
User.find_or_create_by_email('example@example.com', :password => 'example', :first_name => 'Super', :last_name => 'Admin', :terms_and_conditions => true)
The output in 1.9.3 shows ROLLBACK (see below), but I just can't seem to figure out why.
Output (partial) when using 1.9.2:
SQL (0.3ms) INSERT INTO "versions" ("created_at", "event", "item_id", "item_type", "object", "whodunnit") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["created_at", Wed, 10 Oct 2012 13:57:07 UTC +00:00], ["event", "create"], ["item_id", 20], ["item_type", "OrderType"], ["object", nil], ["whodunnit", nil]]
Currency Load (1.1ms) SELECT "currencies".* FROM "currencies" WHERE "currencies"."code" = 'USD' LIMIT 1
SQL (2.4ms) INSERT INTO ..
(continues with the next insert statement)
Output (partial) when using 1.9.3:
SQL (0.3ms) INSERT INTO "versions" ("created_at", "event", "item_id", "item_type", "object", "whodunnit") VALUES ($1, $2, $3, $4, $5, $6) RETURNING "id" [["created_at", Wed, 10 Oct 2012 12:29:49 UTC +00:00], ["event", "create"], ["item_id", 16], ["item_type", "OrderType"], ["object", nil], ["whodunnit", nil]]
Currency Load (0.3ms) SELECT "currencies".* FROM "currencies" WHERE "currencies"."code" = 'USD' LIMIT 1
(0.1ms) ROLLBACK
=> #<User id: 4, first_name: "Super", last_name: "Admin", admin_notes: nil, email: "example@example.com", ...
(stops)
I am thinking this could be an issue with Devise but am not sure.
Would appreciate any help!
Update Oct 19:
I found out that the cause of the problem is an after_create
callback in user.rb that creates a "broker" (through the broker model) where it sets commission = 9.95
From the annotation in broker.rb:
# commission :decimal(, )
And more from broker.rb:
belongs_to :user
PRICE_REGEX = /^([1-9]\d{0,20}|0)(\.\d{0,3})?$/
PRICE_ERROR_MESSAGE = "Must be a number. If you want to include decimals, please use comma as decimal separator. Periods (.) = thousand separator cannot be used."
validates :commission, :format => {:with => PRICE_REGEX, :message => PRICE_ERROR_MESSAGE }, :allow_blank => true
As written above, setting broker commission to 9.95 works fine with ruby 1.9.2 but fails with ruby 1.9.3.
When saving it through rails console in 1.9.3, I get an "ActiveRecord::RecordInvalid: Validation failed..." error. No error in 1.9.2.
If I set it to 10 instead of 9.95 it works in both 1.9.2 and 1.9.3 (broker commission is set to 10).
If I set it to 9,95 (comma, not period) the user and broker is created fine but the broker commission is set to 0.
As the validation error message says, periods (.) are not allowed so it makes sense that the validation fails, but then it would have been a bug in ruby 1.9.2 that had it work before I switched to 1.9.3.
Any good explanation would be welcome :-)
After failed save check @user.errors it may have a clue
EDIT
In your Rails console
@user = User.find_or_create_by_email('example@example.com', :password => 'example', :first_name => 'Super', :last_name => 'Admin', :terms_and_conditions => true)
@user.errors
or
@user.errors.full_messages
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.