Skip to content

Commit

Permalink
before_filter
Browse files Browse the repository at this point in the history
authorize メソッドを login をのぞくすべてのアクションの前にフックして実行
  • Loading branch information
kyanny committed Jan 25, 2010
1 parent f4a5ca6 commit f82ae74
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 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
Expand All @@ -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

0 comments on commit f82ae74

Please sign in to comment.