# Generator

**url\_for 方法的重要组成部分。**

```ruby
module ActionDispatch
  module Routing
    class RouteSet
      def generate(route_key, options, recall = {})
        Generator.new(route_key, options, recall, self).generate
      end
    end
  end
end
```

生成失败的话，会报 UrlGenerationError 错误。

各个实例方法：

```ruby
generate

# 以下几个方法 initialize 时被调用
normalize_recall!
normalize_options!
normalize_controller_action_id!
use_relative_controller!
normalize_controller!
normalize_action!
```

initialize 和 `generate` 对外提供的接口。

除上述外，还有：

```
use_recall_for

controller
current_controller

different_controller?
```

和

```ruby
attr_reader :options, :recall, :set, :named_route
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kelby.gitbook.io/rails-beginner-s-guide/actiondispatch_routeset/class_generator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
