lib/usher/interface/rails23.rb in usher-0.8.0 vs lib/usher/interface/rails23.rb in usher-0.8.1

- old
+ new

@@ -91,30 +91,42 @@ def install_helpers(destinations = [ActionController::Base, ActionView::Base], regenerate_code = false) #*_url and hash_for_*_url Array(destinations).each do |d| d.module_eval { include Helpers } @router.named_routes.keys.each do |name| @module.module_eval <<-end_eval # We use module_eval to avoid leaks - def #{name}_url(options = {}) - ActionController::Routing::Routes.generate(options, {}, :generate, :#{name}) + def #{name}_url(*args) + UsherRailsRouter.generate(args, {}, :generate, :#{name}) end - def #{name}_path(options = {}) - ActionController::Routing::Routes.generate(options, {}, :generate, :#{name}) + def #{name}_path(*args) + UsherRailsRouter.generate(args, {}, :generate, :#{name}) end end_eval end d.__send__(:include, @module) @router.named_routes.instance_eval " def helpers { } end " + unless @module.const_defined?(:UsherRailsRouter) + @module.const_set(:UsherRailsRouter, self) + end + @router.named_routes.helpers.__send__(:extend, @module) end end - def generate(options, recall = {}, method = :generate, route_name = nil) - route = if(route_name) + def generate(args, recall = {}, method = :generate, route_name = nil) + if args.is_a?(Hash) + options = args + args = nil + else + args = Array(args) + options = args.last.is_a?(Hash) ? args.pop : {} + end + + route = if route_name @router.named_routes[route_name] else merged_options = options merged_options[:controller] = recall[:controller] unless options.key?(:controller) unless options.key?(:action) @@ -123,10 +135,10 @@ path_for_options(merged_options) end case method when :generate merged_options ||= recall.merge(options) - url = generate_url(route, merged_options) + url = generate_url(route, args ? args << merged_options : merged_options) url.slice!(-1) if url[-1] == ?/ url else raise "method #{method} not recognized" end