許可されていないユーザーが特定のアクションにアクセスできないように保護しようとしています。
これが私のコントローラーからの小さな例です:
class RestaurantsController < ApplicationController
  before_filter :require_admin, :only => [:new, :create, :update, :edit, :destroy]
    #...yada yada yada...
end
そして、私のApplicationController(多くのコントローラーで同じアクションを保護する必要があるため)にヘルパーメソッドを配置したので、繰り返しません。
class ApplicationController < ActionController::Base
  protect_from_forgery
  private
  def current_user
    @current_user ||= User.find(session[:user_id]) if session[:user_id]
  end
  def require_admin
    ???
  end
  helper_method :current_user
end
次のことを行うために、require_adminメソッドから何を返す必要がありますか。
- current_user管理者でない場合はフローを防止します。
- current_useradminの場合、通常のフローを許可します。
require_adminまた、として配置する必要がありhelper_methodますか?
私はビットを処理する方法をis admin?知っています。フィルターによって呼び出されているヘルパーメソッドから何を返すかを知る必要があります。
助言がありますか?