lib/usher/interface/rails2_interface.rb in joshbuddy-usher-0.3.0 vs lib/usher/interface/rails2_interface.rb in joshbuddy-usher-0.3.2

- old
+ new

@@ -32,22 +32,23 @@ if !@controller_route_added && path =~ %r{^/?:controller/:action$} add_route('/:controller', options.merge({:action => 'index'})) @controller_route_added = true end - - options[:action] = 'index' unless options[:action] + options[:action] = 'index' unless options[:action] + + path[0, 0] = '/' unless path[0] == ?/ route = @usher.add_route(path, options) - raise "your route must include a controller" unless route.primary_path.dynamic_set.include?(:controller) || route.params.include?(:controller) + raise "your route must include a controller" unless route.primary_path.dynamic_set.include?(:controller) || route.params.first.include?(:controller) route end def recognize(request) node = @usher.recognize(request) params = node.params.inject({}){|h,(k,v)| h[k]=v; h } - request.path_parameters = (node.params.empty? ? node.path.route.params : node.path.route.params.merge(params)).with_indifferent_access + request.path_parameters = (node.params.empty? ? node.path.route.params.first : node.path.route.params.first.merge(params)).with_indifferent_access "#{request.path_parameters[:controller].camelize}Controller".constantize rescue raise ActionController::RoutingError, "No route matches #{request.path.inspect} with #{request.inspect}" end @@ -68,17 +69,19 @@ @usher.named_routes[route_name] else merged_options = options merged_options[:controller] = recall[:controller] unless options.key?(:controller) unless options.key?(:action) - options[:action] = nil + options[:action] = '' end route_for_options(merged_options) end case method when :generate merged_options ||= recall.merge(options) - generate_url(route, merged_options) + url = generate_url(route, merged_options) + url.slice!(-1) if url[-1] == ?/ + url else raise "method #{method} not recognized" end end