由于得到一个属性,我以下结构:Rails3中has_and_belongs_to_many - 错误从连接表
class A < ActiveRecord::Base
has_and_belongs_to_many :bs, :class_name => "B", :join_table => "ab"
end
class AB < ActiveRecord::Base
#ab has a date column "creation_date"
#ab also has a text column "creatior"
end
class B < ActiveRecord::Base
end
我成功地检索 “CREATION_DATE” 属性中rails console
console> A.find(1).bs.first.creation_date
=> "14/08/1874"
在控制器
@a = A.find(1)
@bs = a.bs
但在视图(部分)中使用它,我得到以下错误
bs.each do |b|
b.b_attribute #this is O.K.
b.creation_date # cause error => undefined method `creation_date` for #<B:...>
end
# also try to debug in partial
A.find(1).bs.first.creation_date #=> this return data correctly
如上图所示的问题,什么都可能导致undefined method
而直接的属性仍然可以访问。
任何人都知道我的代码有什么问题?