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

I have this request

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

I used rails 3.2.17 and now I am upgrading to rails 4.0.4. I got this error

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'

I solve it by modifying the request

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

But still I get a syntax error

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

What is wrong with the request? Someone explain to me about this. I sent this question, but can not find the answer.

+4
source share
1 answer

Solve this problem by updating your request.

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

Source: https://habr.com/ru/post/1532090/


All Articles