【问题标题】:Rails activerecord .select causing object to have all nil attributesRails activerecord .select 导致对象具有所有 nil 属性
【发布时间】:2013-07-04 18:35:34
【问题描述】:

我正在使用 Rails 3.2.13、Ruby 2.0.0p-p247 和 Spree 2.0.3。

在 rails 控制台或我的实际应用程序中使用 activerecord,如果我运行:Spree::Product.select(:permalink).first 我得到 #<Spree::Product permalink: nil>

但是,如果我运行Spree::Product.first.permalink,我会得到"test",这是预期的永久链接。此外,Spree::Product.first 返回产品的整个 activerecord 关系。

我尝试在RAILS_ENV=development rails c 中运行Spree::Product.create(name: "test", price: "100"),它按预期工作。如果我尝试使用RAILS_ENV=test rails c,我会得到一个 SQL 回滚和一个NoMethodError: undefined method '[]' for nil:NilClass

知道为什么这只发生在测试环境中吗?

【问题讨论】:

  • 你的测试数据库是最新的吗?

标签: ruby-on-rails spree


【解决方案1】:

这原来是spreei18n gem 的一个错误,我提交了一个拉取请求。

https://github.com/spree/spree/commit/09b55f7be8720f0d6d16822f4ce23c961d1c66f5

【讨论】:

    猜你喜欢
    • 2019-09-16
    • 2018-11-18
    • 1970-01-01
    • 2019-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多