[英]rake assets:precompile fails after ruby 1.9.2 -> 1.9.3 upgrade
[英]Create new user works with ruby 1.9.2 but fails with ruby 1.9.3
我正在使用Rails 3.2.8和Devise 2.1.2(最新),并且对为什么我可以使用完全相同的代码库创建用户使用Ruby 1.9.2很好,但不能使用Ruby 1.9.3感到困惑。
Rails控制台:
User.find_or_create_by_email('example@example.com', :password => 'example', :first_name => 'Super', :last_name => 'Admin', :terms_and_conditions => true)
1.9.3中的输出显示ROLLBACK(请参见下文),但我似乎无法弄清楚原因。
使用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)
使用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)
我认为这可能是Devise的问题,但不确定。
将不胜感激!
10月19日更新:
我发现问题的原因是user.rb中的after_create
回调创建了一个“经纪人”(通过代理模型),在其中设置佣金= 9.95
从broker.rb中的注释中:
# commission :decimal(, )
还有来自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
如上文所述,将经纪人佣金设置为9.95可以在ruby 1.9.2上正常工作,但在ruby 1.9.3下无法正常工作。
通过1.9.3中的rails控制台保存它时,出现“ ActiveRecord :: RecordInvalid:验证失败...”错误。 1.9.2没有错误。
如果我将其设置为10而不是9.95,则它可以在1.9.2和1.9.3中使用(经纪人佣金设置为10)。
如果将其设置为9,95(逗号,而不是句点),则可以很好地创建用户和代理,但将代理佣金设置为0。
如验证错误消息所述,不允许使用句点(。),因此验证失败是有道理的,但是在我切换到1.9.3之前,这可能是ruby 1.9.2中的一个错误,它可以正常工作。
任何好的解释都将受到欢迎:-)
保存失败后,检查@ user.errors可能有一个提示
编辑
在您的Rails控制台中
@user = User.find_or_create_by_email('example@example.com', :password => 'example', :first_name => 'Super', :last_name => 'Admin', :terms_and_conditions => true)
@user.errors
要么
@user.errors.full_messages
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.