Rails升级语法错误,意外' \ n',期待=> (的SyntaxError)

时间:2014-03-17 07:14:33

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

我有这个查询

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问题,但找不到答案。

1 个答案:

答案 0 :(得分:2)

通过更新查询解决此问题

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