From Rails Docs
"Rails 4.0 requires applications to use a callable object such as Proc or lambda:"
scope :active, where(active: true)
With this in mind, you can easily rewrite the code as such:
scope :by_post_status, lambda { |post_status| where('post_status = ?', post_status) } scope :published, lambda { by_post_status("public") } scope :draft, lambda { by_post_status("draft") }
If you have many different statuses that you want to maintain, and find it cumbersome, the following might work for you:
post_statuses = %I[public draft private published ...] scope :by_post_status, -> (post_status) { where('post_status = ?', post_status) } post_statuses.each {|s| scope s, -> {by_post_status(s.to_s)} }
wvandaal
source share