使用form_for时rails 3 undefined方法`_index_path'

时间:2011-07-05 10:22:38

标签: ruby-on-rails-3

我最近创建了一个新的rails 3应用程序,使用我为Rails 2编写的代码,同时升级它以匹配新的API。

我有以下代码:

#routes.rb:
FtpMgmt::Application.routes.draw do
    resources :accounts
    root :to => "accounts#index"
    match ':controller(/:action(/:id(.:format)))'
end

#new.html.erb
<% form_for(@account) do |f| %>
...
<% end %>

#accounts_controller.rb
class AccountsController < ApplicationController
    respond_to :html, :xml, :json
    def new
        @account = Accounts.new
        respond_with(@account)
    end
end

我得到的错误是:

Showing /opt/rails/ftp_mgmt/app/views/accounts/new.html.erb where line #3 raised: 
undefined method `accounts_index_path' for #<#<Class:0x0000000a28a758>:0x0000000a269b70>

你有什么想法我可以解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

@account = Accounts.new

应该是

@account = Account.new

另外

<% form_for(@account) do |f| %>

应该是

<%= form_for(@account) do |f| %>