Upgrading Rails 3.2. to Rails 4. I have the following scope:
# Rails 3.2
scope :by_post_status, lambda { |post_status| where("post_status = ?", post_status) }
scope :published, by_post_status("public")
scope :draft, by_post_status("draft")
# Rails 4.1.0
scope :by_post_status, -> (post_status) { where('post_status = ?', post_status) }
But I couldn't find out how to do the 2nd and 3rd lines. How can I create another scope from the first scope?
From the Rails edge docs
With this in mind, you can easily rewrite you code as such:
In the event that you have many different statuses that you wish to support and find this to be cumbersome, the following may suit you:
Very simple, just same lambda without arguments:
or more shorted: