基本的に、単純なRails拡張機能を実装して、コントローラーのメソッドの重大度を定義し、メソッドの使用を適切に制限できるようにします。たとえば、抽象スーパークラスでデフォルトのRESTfulアクションをそのように定義します。
view_methods :index, :show
edit_methods :new, :create, :edit, :update
destroy_methods :destroy
次に、非抽象コントローラー呼び出しでダウンします。
edit_methods :sort
その特定のコントローラーに編集レベルのメソッドとしてsortメソッドを追加します。
次に、before_filterを使用して、現在実行されているアクションのレベルを確認し、現在のユーザーが実行できないとロジックが判断した場合は、それを中止できます。
問題は、この種の構造を設定する方法を理解するのに苦労していることです。私はこれまでにこのようなことを試しました:
class ApplicationController
@@view_methods = Array.new
@@edit_methods = Array.new
@@destroy_methods = Array.new
def self.view_methods(*view_methods)
class_variable_set(:@@view_methods, class_variable_get(:@@view_methods) << view_methods.to_a)
end
def self.edit_methods(*edit_methods)
class_variable_set(:@@edit_methods, self.class_variable_get(:@@edit_methods) << edit_methods.to_a)
end
def self.destroy_methods(*destroy_methods)
@@destroy_methods << destroy_methods.to_a
end
def self.testing
return @@edit_methods
end
view_methods :index, :show
edit_methods :new, :create, :edit, :update
destroy_methods :destroy
end
上記の3つの方法は、私が試したことを示すために、意図的に異なります。3つ目は機能しますが、どのコントローラーをテストしても同じ結果が返されます。おそらく、クラス変数がアプリケーションコントローラに格納されているため、グローバルに変更されます。
どんな助けでも大歓迎です。