任何善良的人都可以看看这个,看看代码有什么问题。我真的不能撤回关联表中的字段!我的问题是什么?
看法:
<% @playersname.each do |p|%>
<ul>
<li><%= p.name %></li>
<li><%= p.result.inspect %></li>
</ul>
控制器:
class ResultsController < ApplicationController
def index
@playersname = Player.all
end
end
模型:
class Player < ActiveRecord::Base
attr_accessible :name
belongs_to :result
end
class Result < ActiveRecord::Base
# attr_accessible :title, :body
has_many :player
end
迁移:
class CreatePlayers < ActiveRecord::Migration
def change
create_table :players do |t|
t.string "name"
t.references :results
t.timestamps
end
end
end
class CreateResults < ActiveRecord::Migration
def change
create_table :results do |t|
t.string "result", :limit => 40
t.string "cal", :limit => 40
t.string "sum",:limit => 300
t.timestamps
end
end
end