ruby - Strange results with model scope -


i have following scope on model.

class programmeinstance  < activerecord::base   # more code    scope :published, -> { where(published: true) }   scope :order_by_start_date, -> { order(:start_date) }   scope :future_with_offset, -> { where("start_date >= ?", date.today - 7.days) }   scope :upcoming_with_offset, -> { future_with_offset.published.order_by_start_date }    # more code end 

i used scope query list returned rails

programme_instances.upcoming_with_offset 

this returns empty result set. however, if make call contents of scope instead of scope so

programme_instances.future_with_offset.published.order_by_start_date 

i results returned.

there must don't know scopes. can explain why?

thanks.

class programmeinstance  < activerecord::base   scope :future_with_offset, -> { where(condition) }   scope :published, -> { where(published: true) }   scope :order_by_start_date, order('start_date') end 

you can call in controller as

programmeinstance.future_with_offset.published.order_by_start_date 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -