1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #8455 from frodsan/actionize

Actionize: Use `_action` callbacks in documentation and code
This commit is contained in:
Xavier Noria 2012-12-07 11:52:42 -08:00
commit 9cb91f9329
14 changed files with 28 additions and 28 deletions

View file

@ -53,7 +53,7 @@ module AbstractController
skip_after_action(*names) skip_after_action(*names)
skip_around_action(*names) skip_around_action(*names)
end end
alias_method :skip_filter, :skip_action_callback alias_method :skip_filter, :skip_action_callback
# Take callback names and an optional callback proc, normalize them, # Take callback names and an optional callback proc, normalize them,
@ -91,7 +91,7 @@ module AbstractController
# :call-seq: prepend_before_action(names, block) # :call-seq: prepend_before_action(names, block)
# #
# Prepend a callback before actions. See _insert_callbacks for parameter details. # Prepend a callback before actions. See _insert_callbacks for parameter details.
# Aliased as prepend_before_action. # Aliased as prepend_before_filter.
## ##
# :method: skip_before_action # :method: skip_before_action
@ -206,7 +206,7 @@ module AbstractController
end # end end # end
alias_method :skip_#{callback}_filter, :skip_#{callback}_action alias_method :skip_#{callback}_filter, :skip_#{callback}_action
# *_action is the same as append_*_action # *_action is the same as append_*_action
alias_method :append_#{callback}_action, :#{callback}_action # alias_method :append_before_action, :before_action alias_method :append_#{callback}_action, :#{callback}_action # alias_method :append_before_action, :before_action
alias_method :append_#{callback}_filter, :#{callback}_action # alias_method :append_before_filter, :before_action alias_method :append_#{callback}_filter, :#{callback}_action # alias_method :append_before_filter, :before_action

View file

@ -32,14 +32,14 @@ module ActionController
# ==== Options # ==== Options
# * <tt>host</tt> - Redirect to a different host name # * <tt>host</tt> - Redirect to a different host name
# * <tt>only</tt> - The callback should be run only for this action # * <tt>only</tt> - The callback should be run only for this action
# * <tt>except</tt> - The callback should be run for all actions except this action # * <tt>except</tt> - The callback should be run for all actions except this action
# * <tt>if</tt> - A symbol naming an instance method or a proc; the callback # * <tt>if</tt> - A symbol naming an instance method or a proc; the callback
# will be called only when it returns a true value. # will be called only when it returns a true value.
# * <tt>unless</tt> - A symbol naming an instance method or a proc; the callback # * <tt>unless</tt> - A symbol naming an instance method or a proc; the callback
# will be called only when it returns a false value. # will be called only when it returns a false value.
def force_ssl(options = {}) def force_ssl(options = {})
host = options.delete(:host) host = options.delete(:host)
before_filter(options) do before_action(options) do
force_ssl_redirect(host) force_ssl_redirect(host)
end end
end end

View file

@ -25,7 +25,7 @@ module ActionController
# the regular HTML interface is protected by a session approach: # the regular HTML interface is protected by a session approach:
# #
# class ApplicationController < ActionController::Base # class ApplicationController < ActionController::Base
# before_filter :set_account, :authenticate # before_action :set_account, :authenticate
# #
# protected # protected
# def set_account # def set_account
@ -68,7 +68,7 @@ module ActionController
module ClassMethods module ClassMethods
def http_basic_authenticate_with(options = {}) def http_basic_authenticate_with(options = {})
before_filter(options.except(:name, :password, :realm)) do before_action(options.except(:name, :password, :realm)) do
authenticate_or_request_with_http_basic(options[:realm] || "Application") do |name, password| authenticate_or_request_with_http_basic(options[:realm] || "Application") do |name, password|
name == options[:name] && password == options[:password] name == options[:name] && password == options[:password]
end end
@ -124,7 +124,7 @@ module ActionController
# USERS = {"dhh" => "secret", #plain text password # USERS = {"dhh" => "secret", #plain text password
# "dap" => Digest::MD5.hexdigest(["dap",REALM,"secret"].join(":"))} #ha1 digest password # "dap" => Digest::MD5.hexdigest(["dap",REALM,"secret"].join(":"))} #ha1 digest password
# #
# before_filter :authenticate, except: [:index] # before_action :authenticate, except: [:index]
# #
# def index # def index
# render text: "Everyone can see me!" # render text: "Everyone can see me!"
@ -317,7 +317,7 @@ module ActionController
# class PostsController < ApplicationController # class PostsController < ApplicationController
# TOKEN = "secret" # TOKEN = "secret"
# #
# before_filter :authenticate, except: [ :index ] # before_action :authenticate, except: [ :index ]
# #
# def index # def index
# render text: "Everyone can see me!" # render text: "Everyone can see me!"
@ -340,7 +340,7 @@ module ActionController
# the regular HTML interface is protected by a session approach: # the regular HTML interface is protected by a session approach:
# #
# class ApplicationController < ActionController::Base # class ApplicationController < ActionController::Base
# before_filter :set_account, :authenticate # before_action :set_account, :authenticate
# #
# protected # protected
# def set_account # def set_account

View file

@ -2,9 +2,9 @@ require 'abstract_unit'
class HttpBasicAuthenticationTest < ActionController::TestCase class HttpBasicAuthenticationTest < ActionController::TestCase
class DummyController < ActionController::Base class DummyController < ActionController::Base
before_filter :authenticate, :only => :index before_action :authenticate, only: :index
before_filter :authenticate_with_request, :only => :display before_action :authenticate_with_request, only: :display
before_filter :authenticate_long_credentials, :only => :show before_action :authenticate_long_credentials, only: :show
http_basic_authenticate_with :name => "David", :password => "Goliath", :only => :search http_basic_authenticate_with :name => "David", :password => "Goliath", :only => :search

View file

@ -4,8 +4,8 @@ require 'active_support/key_generator'
class HttpDigestAuthenticationTest < ActionController::TestCase class HttpDigestAuthenticationTest < ActionController::TestCase
class DummyDigestController < ActionController::Base class DummyDigestController < ActionController::Base
before_filter :authenticate, :only => :index before_action :authenticate, only: :index
before_filter :authenticate_with_request, :only => :display before_action :authenticate_with_request, only: :display
USERS = { 'lifo' => 'world', 'pretty' => 'please', USERS = { 'lifo' => 'world', 'pretty' => 'please',
'dhh' => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":"))} 'dhh' => ::Digest::MD5::hexdigest(["dhh","SuperSecret","secret"].join(":"))}

View file

@ -2,9 +2,9 @@ require 'abstract_unit'
class HttpTokenAuthenticationTest < ActionController::TestCase class HttpTokenAuthenticationTest < ActionController::TestCase
class DummyController < ActionController::Base class DummyController < ActionController::Base
before_filter :authenticate, :only => :index before_action :authenticate, only: :index
before_filter :authenticate_with_request, :only => :display before_action :authenticate_with_request, only: :display
before_filter :authenticate_long_credentials, :only => :show before_action :authenticate_long_credentials, only: :show
def index def index
render :text => "Hello Secret" render :text => "Hello Secret"

View file

@ -13,7 +13,7 @@ module Another
head :status => 406 head :status => 406
end end
before_filter :redirector, :only => :never_executed before_action :redirector, only: :never_executed
def never_executed def never_executed
end end

View file

@ -1139,7 +1139,7 @@ end
# For testing layouts which are set automatically # For testing layouts which are set automatically
class PostController < AbstractPostController class PostController < AbstractPostController
around_filter :with_iphone around_action :with_iphone
def index def index
respond_to(:html, :iphone, :js) respond_to(:html, :iphone, :js)

View file

@ -3,7 +3,7 @@ require 'abstract_unit'
# Tests the controller dispatching happy path # Tests the controller dispatching happy path
module Dispatching module Dispatching
class SimpleController < ActionController::Base class SimpleController < ActionController::Base
before_filter :authenticate before_action :authenticate
def index def index
render :text => "success" render :text => "success"

View file

@ -14,7 +14,7 @@ module RenderContext
include ActionView::Context include ActionView::Context
# 2) Call _prepare_context that will do the required initialization # 2) Call _prepare_context that will do the required initialization
before_filter :_prepare_context before_action :_prepare_context
def hello_world def hello_world
@value = "Hello" @value = "Hello"

View file

@ -37,7 +37,7 @@ end
class TestController < ActionController::Base class TestController < ActionController::Base
protect_from_forgery protect_from_forgery
before_filter :set_variable_for_layout before_action :set_variable_for_layout
class LabellingFormBuilder < ActionView::Helpers::FormBuilder class LabellingFormBuilder < ActionView::Helpers::FormBuilder
end end
@ -137,7 +137,7 @@ class TestController < ActionController::Base
def conditional_hello_with_bangs def conditional_hello_with_bangs
render :action => 'hello_world' render :action => 'hello_world'
end end
before_filter :handle_last_modified_and_etags, :only=>:conditional_hello_with_bangs before_action :handle_last_modified_and_etags, :only=>:conditional_hello_with_bangs
def handle_last_modified_and_etags def handle_last_modified_and_etags
fresh_when(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ]) fresh_when(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ])
@ -710,7 +710,7 @@ class TestController < ActionController::Base
render :action => "calling_partial_with_layout", :layout => "layouts/partial_with_layout" render :action => "calling_partial_with_layout", :layout => "layouts/partial_with_layout"
end end
before_filter :only => :render_with_filters do before_action only: :render_with_filters do
request.format = :xml request.format = :xml
end end

View file

@ -68,7 +68,7 @@ class RescueController < ActionController::Base
render :text => 'io error' render :text => 'io error'
end end
before_filter(:only => :before_filter_raises) { raise 'umm nice' } before_action(only: :before_filter_raises) { raise 'umm nice' }
def before_filter_raises def before_filter_raises
end end

View file

@ -5,7 +5,7 @@ module ShowExceptions
use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public") use ActionDispatch::ShowExceptions, ActionDispatch::PublicExceptions.new("#{FIXTURE_LOAD_PATH}/public")
use ActionDispatch::DebugExceptions use ActionDispatch::DebugExceptions
before_filter :only => :another_boom do before_action only: :another_boom do
request.env["action_dispatch.show_detailed_exceptions"] = true request.env["action_dispatch.show_detailed_exceptions"] = true
end end

View file

@ -4,7 +4,7 @@ class ViewLoadPathsTest < ActionController::TestCase
class TestController < ActionController::Base class TestController < ActionController::Base
def self.controller_path() "test" end def self.controller_path() "test" end
before_filter :add_view_path, :only => :hello_world_at_request_time before_action :add_view_path, only: :hello_world_at_request_time
def hello_world() end def hello_world() end
def hello_world_at_request_time() render(:action => 'hello_world') end def hello_world_at_request_time() render(:action => 'hello_world') end