Re: [Rails] Logic duplication in scopes & predicates

2014-09-16 Thread Vivek Sampara
tiny update - scope :recommended, -> { where(self.recommended_condition) } def recommended? eval(self.class.recommended_condition("||")) end def self.recommended_condition(selector == "OR") 'editors_selection #{selector} rating > 9' end On Tue, Sep 16, 2014 at 1:33 PM, Vivek Sampara wrot

Re: [Rails] Logic duplication in scopes & predicates

2014-09-16 Thread Vivek Sampara
scope :recommended, -> { where(recommended_condition) } def recommended? eval(recommended_condition("||")) end def recommended_condition(selector = "OR") "editors_selection #{selector} rating > 9" end On Tue, Sep 16, 2014 at 7:33 AM, wrote: > Consider something like that in a model: > > s

[Rails] Logic duplication in scopes & predicates

2014-09-15 Thread fey
Consider something like that in a model: scope :recommended, -> { where('editors_selection OR rating > 9') } def recommended? editors_selection? || rating > 9 end How to DRY it up? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To u