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?
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?
scope :recommended, -> { where(recommended_condition) }
def recommended?
eval(recommended_condition("||"))
end
def recommended_condition(selector = “OR”)
“editors_selection #{selector} rating > 9”
end
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 S. [email protected]
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs