我最近创建了一个新的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>
你有什么想法我可以解决这个问题吗?
答案 0 :(得分:1)
@account = Accounts.new
应该是
@account = Account.new
另外
<% form_for(@account) do |f| %>
应该是
<%= form_for(@account) do |f| %>