我有一个包含很多内容的应用程序。现在我有一个布尔值叫做featured
. 标记时feature
,我希望此内容显示在页面顶部。现在,我对内容有一个范围顺序,但我不确定如何首先显示特色项目。有什么想法吗?以下是我对内容的小范围:
scope :published, where(:published => true )
scope :unpublished, where(:published => false )
scope :ordering, order("published_date desc")
scope :feature, where(feature: true )
这是我的家庭控制器显示内容的样子:
def index
@contents = Content.includes(:author).published.ordering
@collections = @user.try(:collections)
@categories = Category.includes(:subcategories).all
end
似乎有比 if else 语句更好的方法来做到这一点。建议?我一直在查看订单文档,但没有找到任何针对这种情况的具体内容。
使用:
Rails 3.2.14
Ruby 1.9.3