I would like to understand the Rails 3 routing deeper – to fix a problem I’m having. I’m trying to use the datagrid gem. I have this:
class UsersController < ApplicationController
def index
@admin_console = AdminConsole.new(params[:admin_console])
...
and then in users’s index.html.erb:
<%= form_for @admin_console, :html => {:method => :get} do |f| -%>
<% @admin_console.filters.each do |filter| -%>
...
and I get an error that “admin_consoles_path” is an undefined method.
In routes, I just have this:
resources :users
I don’t have an AdminConsoleController; I just have a model for it.
I’d like to understand why I need to have AdminConsole in routes, if I do.
The form_for helper is looking for the admin_consoles_path because you are using the shortened version of the helper.
This and specifically section 2.3, explains what is actually happening when using form_for
I believe you need a controller action to create the AdminConsole, but it doesn’t necessarily need it’s own controller if you specify the url as in the sample above (although it may not be best practice).