ユーザーと管理者など、プロジェクトに2つのデバイス(バージョン:1.4.8)モデルを実装しました。
2 つのデバイスを備えた同じコントローラーで単一アクションの認証を構成するオプションはありますか? CartsController の例:
index, show -> can access either admin or user
create, update, delete -> can access admin only
現在、application_controller.rbから以下のメソッドを呼び出して認証しています
def authenticate_user_or_admin!
unless user_signed_in? or admin_signed_in?
redirect_to root_url , :flash => {:alert => "You need to sign in as admin/user before continuing..".html_safe }
end
end
carts_controler.rb で
class CartsControler < ApplicationController
before_filter :authenticate_user_or_admin!, :only => [:index, :show]
before_filter: :authenticate_admin!, :except => [:index, :show]
デバイスは、複数のデバイス モデルを認証するためのデフォルト オプションを提供していますか?
この問題を解決する適切な方法はありますか? または他のより良い解決策はありますか?