2013-02-01 83 views
0

我想深入了解Rails 3的路由 - 以解决我遇到的问题。我正在尝试使用datagrid gem。我有这样的:了解Rails 3与datagrid的路由

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,如果有的话。

回答

0

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

This,特别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(尽管它可能不是最佳实践)。

+0

谢谢。我在课堂上并不一致。我需要重新设计它。感谢您花时间回答我,brennan。 – sploiber

+0

很高兴我能帮到你。 – Brennan