【问题标题】:Rails Upgraded syntax error, unexpected '\n', expecting => (SyntaxError)Rails 升级的语法错误,意外的 '\n',期待 => (SyntaxError)
【发布时间】:2014-04-22 07:44:00
【问题描述】:

我有这个问题

has_many :unused_invitations, :class_name => 'Invitation', :foreign_key => 'inviter_id', :conditions => 'used = false'

我使用的是 rails 3.2.17,现在我正在升级到 rails 4.0.4。我收到了这个错误

DEPRECATION WARNING: The following options in your User.has_many :unused_invitations declaration are deprecated: :conditions. Please use a scope block instead. For example, the following:

    has_many :spam_comments, conditions: { spam: true }, class_name: 'Comment'

should be rewritten as the following:

    has_many :spam_comments, -> { where spam: true }, class_name: 'Comment'

我通过修改查询来解决

has_many :used_invitations, class_name: 'Invitation', foreign_key: 'inviter_id', -> { where used: false}

但我仍然遇到语法错误

syntax error, unexpected '\n', expecting => (SyntaxError)

查询有什么问题?有人会解释一下吗。我已经去了this 的问题,但找不到答案。

【问题讨论】:

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


    【解决方案1】:

    通过更新查询来解决这个问题

    has_many :used_invitations, -> { where used: false}, class_name: 'Invitation', foreign_key: 'inviter_id'
    

    【讨论】:

    • 是的,关键是在其他选项之前声明查找器选项。
    • @TaniaR 在这件事上绞尽脑汁太久了,感谢您的澄清。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 2015-08-19
    • 1970-01-01
    • 2017-09-12
    • 2015-04-02
    • 1970-01-01
    相关资源
    最近更新 更多