Slide 21
Slide 21 text
Implicit vs Explicit API
Active
Record
1 Post.where(state:'published').
2 order('created_at DESC').
3 limit(5)
1 Post.most_recent_published
1 class Post < ActiveRecord::Base
2 def self.most_recent_published(limit = 5)
3 published.recent(limit).order('created_at DESC')
4 end
5
6 private
7 scope :published, ->() { where(state: 'published') }
8 scope :recent, ->(n) { limit(n) }
9 end