- !ruby/object:Pacdoc
attributes:
id: 5
pac_id: 5
doc_id: 1
created_at: 2013-06-26 12:07:33.263881000 Z
updated_at: 2013-06-26 12:07:33.263881000 Z
- !ruby/object:Pacdoc
attributes:
id: 6
pac_id: 5
doc_id: 2
created_at: 2013-06-26 12:07:33.266881000 Z
updated_at: 2013-06-26 12:07:33.266881000 Z
已经在变量@pdocs中收集了上述数据,并且能够挑选出doc_id的值
<%= @pdocs.each do |a| %>
<%= b = a.doc_id %>
<% end%>
现在想用结构 doc_id 从表 'doc' 中检索数据,下面的名称:字符串是模型
models
class Pacdoc < ActiveRecord::Base
attr_accessible :doc_id, :pac_id
belongs_to :pac
belongs_to :doc
end
class Pac < ActiveRecord::Base
attr_accessible :name
validates :name, :presence => :true
has_many :pacdocs
has_many :docs, :through => :pacdocs
end
class Doc < ActiveRecord::Base
attr_accessible :name
validates :name, :presence => :true
has_many :pacdocs
has_many :pacs, :through => :pacdocs
end