Flowdock
method

generate

Importance_0
Ruby on Rails latest stable (v4.0.2) - 0 notes - Class: ActionController::Routing::RouteSet

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v2.3.8) is shown here.

These similar methods exist in v4.0.2:

generate(options, recall = {}, method=:generate) public

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File actionpack/lib/action_controller/routing/route_set.rb, line 358
      def generate(options, recall = {}, method=:generate)
        named_route_name = options.delete(:use_route)
        generate_all = options.delete(:generate_all)
        if named_route_name
          named_route = named_routes[named_route_name]
          options = named_route.parameter_shell.merge(options)
        end

        options = options_as_params(options)
        expire_on = build_expiry(options, recall)

        if options[:controller]
          options[:controller] = options[:controller].to_s
        end
        # if the controller has changed, make sure it changes relative to the
        # current controller module, if any. In other words, if we're currently
        # on admin/get, and the new controller is 'set', the new controller
        # should really be admin/set.
        if !named_route && expire_on[:controller] && options[:controller] && options[:controller][0] != ?/
          old_parts = recall[:controller].split('/')
          new_parts = options[:controller].split('/')
          parts = old_parts[0..-(new_parts.length + 1)] + new_parts
          options[:controller] = parts.join('/')
        end

        # drop the leading '/' on the controller name
        options[:controller] = options[:controller][1..-1] if options[:controller] && options[:controller][0] == ?/
        merged = recall.merge(options)

        if named_route
          path = named_route.generate(options, merged, expire_on)
          if path.nil?
            raise_named_route_error(options, named_route, named_route_name)
          else
            return path
          end
        else
          merged[:action] ||= 'index'
          options[:action] ||= 'index'

          controller = merged[:controller]
          action = merged[:action]

          raise RoutingError, "Need controller and action!" unless controller && action

          if generate_all
            # Used by caching to expire all paths for a resource
            return routes.collect do |route|
              route.__send__(method, options, merged, expire_on)
            end.compact
          end

          # don't use the recalled keys when determining which routes to check
          future_routes, deprecated_routes = routes_by_controller[controller][action][options.reject {|k,v| !v}.keys.sort_by { |x| x.object_id }]
          routes = Routing.generate_best_match ? deprecated_routes : future_routes

          routes.each_with_index do |route, index|
            results = route.__send__(method, options, merged, expire_on)
            if results && (!results.is_a?(Array) || results.first)
              return results
            end
          end
        end

        raise RoutingError, "No route matches #{options.inspect}"
      end
Register or log in to add new notes.