Action Controller:Filters

Published at 6 months ago

before_filter :require_login

skip_before_filter :require_login, :only => [:new, :create]

around_filter :catch_exceptions

before_filter { |controller| redirect_to new_login_url unless controller.send(:logged_in?) }

class ApplicationController < ActionController::Base

before_filter LoginFilter

end

class LoginFilter

def self.filter(controller)

unless logged_in?

controller.flash[:error] = "You must be logged in to access this section"

controller.redirect_to controller.new_login_url

end

end

end

参考:http://rails.learnhub.com/lesson/6373-action-controller-filters

#Ruby on Rails

@http://zfben.com/blog/Action Controller:Filters