私は配列を持っています
[['Part', 'create'], ['Part', 'update'], ['Part', 'delete'], ['Part', 'release'], ['Plan', 'create'], ['Plan', 'update'], ['Plan', 'delete'], ['Plan', 'release'], ['Inspection', 'create'], ['Inspection', 'update'], ['Inspection', 'delete'], ['Inspection', 'release'], ['User', 'create'],['User', 'update']]
部品、計画、検査、作成、更新、削除、リリースの順に並べ替えたい
上記の順序で並べ替えたいのは原因です
Part
has_many plans
Plan
belongs_to :part
has_many inspections
Inspection
belongs_to :plan
cancanを使用して動的な役割と権限を実装しました。ユーザーには、アクション(作成、更新、削除、リリース)のアクセス許可が割り当てられている必要があり、SubjectClass(パーツ、計画、検査、ユーザー)の表示順序はそれらの関係である必要があります。
並べ替えを使用すると、
a.sort
=> [["Inspection", "create"], ["Inspection", "delete"], ["Inspection", "release"], ["Inspection", "update"], ["Part", "create"], ["Part", "delete"], ["Part", "release"], ["Part", "update"], ["Plan", "create"], ["Plan", "delete"], ["Plan", "release"], ["Plan", "update"], ["User", "create"], ["User", "update"]]
a.sort_by{|x, y| x[0] <=> y[0]}
=> [["Part", "create"], ["Part", "update"], ["Part", "delete"], ["Part", "release"], ["Plan", "create"], ["Plan", "update"], ["Plan", "delete"], ["Plan", "release"], ["Inspection", "create"], ["Inspection", "update"], ["Inspection", "delete"], ["Inspection", "release"], ["User", "create"], ["User", "update"]]
インデックス方式はなんとか使えますか?また、新しいサブジェクトクラスとアクションが後で追加される可能性があります。そのため、並べ替え順序が変わる場合があります。