ピン モデル (ユーザー/ショーとピン/インデックス) から生成された 2 つのビューがあります。
ユーザー/ショーでは、デフォルトのスコープを使用してすべてのピンを表示したいと考えています。ピン/インデックスでは、featured_order スコープを使用して「注目の」ピンを一番上に表示し、デフォルトのスコープで続行したいと考えています。
これが私が持っているものですが、何らかの理由ですべてのデフォルトのスコープに戻っています。
class Pin < ActiveRecord::Base
attr_accessible :content, :title
belongs_to :user
# for sorting featured and newest pins first
default_scope order: 'created_at DESC'
scope :featured_order, order('(case when featured then 1 else 0 end) DESC, created_at DESC')
end
私の index.html.erb では、部分 (_pin.html.erb) をレンダリングします。
<%= render @pins %>
私の show.html.erb にはリストがあります:
<% @pins.each do |pin| %>
<%= pin.title %>
<%= pin.content %>
<% end %>