我越來越想在我的Rails應用程序的form_for使用時出現以下錯誤:未定義的方法 'TO_KEY' 錯誤使用的form_for
undefined method `to_key' for #<Table::ActiveRecord_Relation:0x8a09ca8>
我的config/routes.rb文件是:
root 'welcome#index'
post 'foo', as: 'foo', to: 'welcome#index'
的控制器是:
class WelcomeController < ApplicationController
def index
@tables = Table.all
end
def test
@tables = Table.all
end
end
和歡迎/ index.html.erb的看法是:
<p>
<%= form_for @tables, :url => foo_path do |t| %>
<%= t.text_area :name %>
<% end %>
</p>
我試過做文檔中建議的url解決方法,但我仍然得到相同的錯誤。
有誰知道我在做什麼錯?我想更多地瞭解這個bug,以便我可以更好地處理它。
以rails開頭請參閱此http://guides.rubyonrails.org/getting_started.html –