How to pass argument to the call method to use the same query class in multiple scopes?
call
class StatusPostsQuery class << self delegate :call, to: :new end def initialize(relation = Post) @relation = relation end def call(value = 'active') @relation.where(status: value) end end
class Post scope :active, StatusPostsQuery scope :inactive, StatusPostsQuery #...? end
Shameless plug: I wrote a RubyGem that can do just that. I hope that helps.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
How to pass argument to the
call
method to use the same query class in multiple scopes?Shameless plug: I wrote a RubyGem that can do just that. I hope that helps.