From f82ae74743791fe2eb132500db76224404e49ec2 Mon Sep 17 00:00:00 2001 From: Kensuke Kaneko Date: Tue, 26 Jan 2010 01:57:51 +0900 Subject: [PATCH] before_filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit authorize メソッドを login をのぞくすべてのアクションの前にフックして実行 --- depot/app/controllers/application.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/depot/app/controllers/application.rb b/depot/app/controllers/application.rb index 0fdcd93..e05ea4a 100644 --- a/depot/app/controllers/application.rb +++ b/depot/app/controllers/application.rb @@ -1,7 +1,9 @@ +# -*- coding: utf-8 -*- # Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base + before_filter :authorize, :except => :login helper :all # include all helpers, all the time # See ActionController::RequestForgeryProtection for details @@ -12,4 +14,12 @@ class ApplicationController < ActionController::Base # Uncomment this to filter the contents of submitted sensitive data parameters # from your application log (in this case, all fields with names like "password"). # filter_parameter_logging :password + + protected + def authorize + unless User.find_by_id(:session[:user_id]) + flash[:notice] = "ログインしてください" + redirect_to :controller => 'admin', :action => 'login' + end + end end