idl*_*ers 16
scope :most_recent, order(created_at: :desc).limit(10)
Run Code Online (Sandbox Code Playgroud)
sca*_*er2 13
使用范围
# Ruby 1.8 style
scope :recent, lambda { |num| order('created_at DESC').limit(num) }
# Ruby 1.9/2.0 style
scope :recent, ->(num) { order('created_at DESC').limit(num) }
Run Code Online (Sandbox Code Playgroud)
用法示例:
<% Organization.recent(10).each do |organization| %>
<li><% link_to organization.name, organization %></li>
<% end %>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
7755 次 |
最近记录: |