2016-08-06 5 views
1

は私が工夫をインストールした場合、私はユーザテーブルのレコードまたは列(私はそれを呼び出すするかどうかはわかりません)に管理者を追加しました:ブール値、デフォルトではfalseですRailsは、管理

で私のroutes.rbを私はこの/ adminのリンク

get 'admin' => 'admin#index' 

を作成していると私は唯一

class AdminController < ApplicationController 
    before_action: I have no idea what to write here 

    def index 
    end 

end 

答えて

2

があなたのコントローラで、次のように試してみてください管理者のためにそれを表示するかどうかはわかりません。

class AdminController < ApplicationController 
    before_action :is_admin? 

    def index 

    end 


    # it will call before every action on this controller 
    def is_admin? 
     # check if user is a admin 
     # if not admin then redirect to where ever you want 
     redirect_to root_path unless current_user.admin? 
    end 

end 
+0

ありがとうございます.is_adminメソッドをプライベートにする必要がありますか? –

+0

はい、プライベートで設定できます。 –

+0

あなたは私の日を救ったので、私はそれを受け入れるつもりだと思うので、ありがとう! –

関連する問題