【发布时间】:2015-11-01 20:02:38
【问题描述】:
由于某种原因,我在此行出现错误。一切似乎都是正确的。
undefined method `datetime' for #<Game:0x87e73f0>
控制台日志截图: www.gyazo.com/0947c493218a3fecdb5849e1e13f181a
app/views/games/_form.html.erb 其中第 4 行提出
<%= f.text_field :datetime %>
迁移文件:
class CreateGames < ActiveRecord::Migration
def change
create_table :games do |t|
t.string :datetime
t.string :location
t.references :team, index: true
t.timestamps null: false
end
end
end
部分形式:
<%= form_for([@team, @team.games.build]) do |f| %>
<p>
<%= f.label :datetime %><br>
<%= f.text_field :datetime %>
</p>
<p>
<%= f.label :location %><br>
<%= f.text_field :location %>
</p>
<br>
<p>
<%= f.submit %>
</p>
<% end %>
路线文件:
Rails.application.routes.draw do
devise_for :users
resources :teams do
resources :members
end
resources :teams do
resources :games
end
root "teams#index"
end
【问题讨论】:
-
向我们显示您看到错误的服务器日志。它将帮助我们帮助您
-
您在创建迁移后做了
rake db:migrate吗? -
@ArupRakshit for Game.column_names 我得到了:=> ["id", "date_time", "location", "team_id", "created_at", "updated_at"]
-
@matanco 对于 Game.first 我得到:SELECT "game".* FROM "games" ORDER BY "games"。 "id" ASC LIMIT 1 => 无
-
所以你必须使用
date_time而不是datetime。不确定,在创建实际表时,您的迁移给定名称如何更改。 :)
标签: ruby-on-rails forms partial-views nomethoderror