mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor handling of action normalization
Reference: Bloody mess internals http://gusiev.com/slides/rails_contribution/static/#40
This commit is contained in:
parent
633be2cbbd
commit
310fc2b8c1
1 changed files with 13 additions and 11 deletions
|
@ -514,11 +514,12 @@ module ActionDispatch
|
||||||
@recall = recall.dup
|
@recall = recall.dup
|
||||||
@set = set
|
@set = set
|
||||||
|
|
||||||
|
normalize_recall!
|
||||||
normalize_options!
|
normalize_options!
|
||||||
normalize_controller_action_id!
|
normalize_controller_action_id!
|
||||||
use_relative_controller!
|
use_relative_controller!
|
||||||
normalize_controller!
|
normalize_controller!
|
||||||
handle_nil_action!
|
normalize_action!
|
||||||
end
|
end
|
||||||
|
|
||||||
def controller
|
def controller
|
||||||
|
@ -537,6 +538,11 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set 'index' as default action for recall
|
||||||
|
def normalize_recall!
|
||||||
|
@recall[:action] ||= 'index'
|
||||||
|
end
|
||||||
|
|
||||||
def normalize_options!
|
def normalize_options!
|
||||||
# If an explicit :controller was given, always make :action explicit
|
# If an explicit :controller was given, always make :action explicit
|
||||||
# too, so that action expiry works as expected for things like
|
# too, so that action expiry works as expected for things like
|
||||||
|
@ -552,8 +558,8 @@ module ActionDispatch
|
||||||
options[:controller] = options[:controller].to_s
|
options[:controller] = options[:controller].to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
if options[:action]
|
if options.key?(:action)
|
||||||
options[:action] = options[:action].to_s
|
options[:action] = (options[:action] || 'index').to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -563,8 +569,6 @@ module ActionDispatch
|
||||||
# :controller, :action or :id is not found, don't pull any
|
# :controller, :action or :id is not found, don't pull any
|
||||||
# more keys from the recall.
|
# more keys from the recall.
|
||||||
def normalize_controller_action_id!
|
def normalize_controller_action_id!
|
||||||
@recall[:action] ||= 'index' if current_controller
|
|
||||||
|
|
||||||
use_recall_for(:controller) or return
|
use_recall_for(:controller) or return
|
||||||
use_recall_for(:action) or return
|
use_recall_for(:action) or return
|
||||||
use_recall_for(:id)
|
use_recall_for(:id)
|
||||||
|
@ -586,13 +590,11 @@ module ActionDispatch
|
||||||
@options[:controller] = controller.sub(%r{^/}, '') if controller
|
@options[:controller] = controller.sub(%r{^/}, '') if controller
|
||||||
end
|
end
|
||||||
|
|
||||||
# This handles the case of action: nil being explicitly passed.
|
# Move 'index' action from options to recall
|
||||||
# It is identical to action: "index"
|
def normalize_action!
|
||||||
def handle_nil_action!
|
if @options[:action] == 'index'
|
||||||
if options.has_key?(:action) && options[:action].nil?
|
@recall[:action] = @options.delete(:action)
|
||||||
options[:action] = 'index'
|
|
||||||
end
|
end
|
||||||
recall[:action] = options.delete(:action) if options[:action] == 'index'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Generates a path from routes, returns [path, params].
|
# Generates a path from routes, returns [path, params].
|
||||||
|
|
Loading…
Reference in a new issue