【问题标题】:Squeel working in Rails Console but not in Controller. Error: undefined method `method' for nil:NilClassSqueel 在 Rails 控制台中工作,但不在控制器中。错误:nil:NilClass 的未定义方法“方法”
【发布时间】:2014-02-19 06:13:57
【问题描述】:

我正在使用 Squeel,但遇到了一个奇怪的问题。以下行在 Rails 控制台中运行良好,但在模型的控制器中运行时出错!

Issue.joins{property.users}.where{property.users.id == 1}

发布belongs_to 属性,并且属性has_and_belongs_to_many 用户。我正在尝试加载与 user_id == 1 相关的所有问题。

当我在 IssuesController 中运行该行时,我收到错误:“undefined method `users' for nil:NilClass”,但它在 Rails 控制台中有效。怎么了?

附:我正在运行 Rails 4.0.3、Ruby 2.0.0 和 Squeel 1.1.1

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-4 squeel


    【解决方案1】:

    试试这个

    my_properties = Property.where{user_id == 1}.select{issue_id}
    Issue.where{id.in(my_properties)}
    

    【讨论】:

      猜你喜欢
      • 2016-05-05
      • 1970-01-01
      • 2012-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-16
      • 1970-01-01
      相关资源
      最近更新 更多