user1780370
user1780370

Reputation: 851

Error in OR condition in include query of Rails 4

I am using Rails 4 application where query use includes.

Query: @courses = Course.includes(:translations).unpublished_status

Where unpublished_status is scope write in Model. (See Below):

 scope :unpublished,  -> { where(published: false) }
 scope :status,  -> { where.not(status: 'active') }
 scope :unpublished_status, -> { unpublished.where.or(status)}

When i run code then got below error:

NoMethodError at /api/v1/unpublished_courses
============================================

> undefined method `or' for #
<Globalize::ActiveRecord::QueryMethods::WhereChain:0x007fe05dbc70d8>

Where is actual issue did not found. Any one have a idea on it.

Thanks

Upvotes: 1

Views: 112

Answers (2)

Vitali Mogilevsky
Vitali Mogilevsky

Reputation: 720

where.or is available only in rails 5 you can check this link.

To 'OR' scopes you can do :

scope :unpublished_status, -> { unpublished || status}
    **OR**
Course.where('published = ? OR status != ?', false, 'active')

Upvotes: 1

Gupta
Gupta

Reputation: 10358

undefined method `or' for #
 <Globalize::ActiveRecord::QueryMethods::WhereChain:0x007fe05dbc70d8>

As it says undefined method for ActiveRecord::QueryMethods::WhereChain:

means or method is not available. To fix this or_scopes.rb , you'd be able to OR your scopes.

Hope this helps you !!!

Upvotes: 0

Related Questions