Skip to content

Commit

Permalink
extract controller and action parsing to a method
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed May 28, 2014
1 parent bc916a7 commit 8d30983
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions actionpack/lib/action_dispatch/routing/mapper.rb
Expand Up @@ -240,25 +240,12 @@ def default_controller_and_action
hash = {} hash = {}
return hash if to.respond_to? :call return hash if to.respond_to? :call


controller = default_controller controller, action = get_controller_and_action(
action = default_action default_controller,

default_action,
case to to,
when Symbol @scope[:module]
action = to.to_s )
when /#/
controller, action = to.split('#')
when String
controller = to
end

if @scope[:module] && !controller.is_a?(Regexp)
if controller =~ %r{\A/}
controller = controller[1..-1]
else
controller = [@scope[:module], controller].compact.join("/")
end
end


if controller.is_a? Regexp if controller.is_a? Regexp
hash[:controller] = controller hash[:controller] = controller
Expand All @@ -277,6 +264,26 @@ def default_controller_and_action
hash hash
end end


def get_controller_and_action(controller, action, to, modyoule)
case to
when Symbol
action = to.to_s
when /#/
controller, action = to.split('#')
when String
controller = to
end

if modyoule && !controller.is_a?(Regexp)
if controller =~ %r{\A/}
controller = controller[1..-1]
else
controller = [modyoule, controller].compact.join("/")
end
end
[controller, action]
end

def check_action!(action) def check_action!(action)
unless action || segment_keys.include?(:action) unless action || segment_keys.include?(:action)
message = "Missing :action key on routes definition, please check your routes." message = "Missing :action key on routes definition, please check your routes."
Expand Down

0 comments on commit 8d30983

Please sign in to comment.