Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have this query

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

I was using 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 query

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

But Still I getting syntax error

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

What is wrong with query ? Will someone explain me about it. I have go this question but can't find the answer.

like image 957
Amrit Dhungana Avatar asked Nov 01 '22 03:11

Amrit Dhungana


1 Answers

Solve this problem by updating the query

has_many :used_invitations, -> { where used: false}, class_name: 'Invitation', foreign_key: 'inviter_id'
like image 84
Amrit Dhungana Avatar answered Nov 09 '22 15:11

Amrit Dhungana