我想更深入地了解Rails3的路由--来解决我遇到的一个问题。我正在尝试使用数据网格宝石。我有这个:
class UsersController < ApplicationController
def index
@admin_console = AdminConsole.new(params[:admin_console])
...然后在users's 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。
发布于 2013-02-02 04:13:07
form_for帮助器正在查找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,那么它不一定需要自己的控制器(尽管这可能不是最佳实践)。
https://stackoverflow.com/questions/14654049
复制相似问题