にHABTMのデータを並べ替え、私は次のデータベースがあります。ユーザー(users/show.html.haml
)のためのビューでレール
class User < ActiveRecord::Base
has_and_belongs_to_many :apps
class App < ActiveRecord::Base
has_and_belongs_to_many :users
を私は、現在のユーザが持っているものでソートすべてのアプリを一覧表示します。
%table
%thead
%tr
%th Name
%th Available
- for app in App.order("??????")
%tr
%td= link_to app.name, app_path(app)
%td
- if @user.apps.include?(app)
%i.icon-ok
- else
%i.icon-remove
私の質問は、並べ替えを行うために何を並べ替えるかです。
user.apps.order @ を。 'App.order(@ user.apps.include?(this))'やそのようなものをどうしたいのですか? –