0
これは初めてのスコープです。私は章のリストを:priority
という整数のフィールドでソートしようとしています。私はスコープのドキュメントを見てきましたが、機能を動作させる方法を理解できないようです。Rails 4スコープが正しくソートされていない
モデル
class Chapter < ActiveRecord::Base
belongs_to :book
scope :priority_sort, -> { order(priority: :asc) }
end
コントローラ
@chapters = Chapter.all.priority_sort
とビュー
<% @book.chapters.each do |chapter| %>
<%= link_to chapter.title, [@book, chapter] %>
<% end %>
は、ビューが現在 優先/ chapter_title
-15
About the authors
3
Chapter 18 Equal pay
-13
Chapter 2 Overview
-4
Chapter 11 Non-exempt employees: determining work time
-11
Chapter 4 Workers not covered by the FLSA
どのように見えるかのビューは、私がここで行方不明です何default_scope { order("priority ASC") }
-15
About the authors
-14
Chapter 1 Snapshot
-13
Chapter 2 Overview
-12
Chapter 3 Covered employers
-11
Chapter 4 Workers not covered by the FLSA
でどのように見えますか?