0

我想更深入地了解 Rails 3 路由 - 以解决我遇到的问题。我正在尝试使用数据网格 gem。我有这个:

class UsersController < ApplicationController
  def index
    @admin_console = AdminConsole.new(params[:admin_console])
    ...

然后在用户的 index.html.erb 中:

<%= form_for @admin_console, :html => {:method => :get} do |f| -%>
  <% @admin_console.filters.each do |filter| -%>
       ...

我得到一个错误,“admin_consoles_path”是一个未定义的方法。

在路线中,我只有这个:

resources :users

我没有 AdminConsoleController;我只有一个模型。如果需要,我想了解为什么我需要在路由中使用 AdminConsole。

4

1 回答 1

0

form_for 助手正在寻找 admin_consoles_path,因为您使用的是助手的缩短版本。

尤其是第 2.3 节,解释了使用 form_for 时实际发生的情况

## Creating a new article
# long-style:
form_for(@article, :url => articles_path)
# same thing, short-style (record identification gets used):
form_for(@article)

我相信您需要一个控制器操作来创建 AdminConsole,但如果您在上面的示例中指定 url,它不一定需要它自己的控制器(尽管它可能不是最佳实践)。

于 2013-02-01T20:13:06.920 回答