Tag: 有许多

Rails:belongs_to vs has_one

有关轨道协会的一个新手问题。 我有一个Bug模型和一个状态模型。 状态基本上只是一个键/值对表。 在可用的select中,我会说Bug has_one Status是最有意义的。 但是,据此 内容belongs_to ContentTemplate。 回过头来看看我如何描述这个问题,你会看到它的工作原理。 通过belongs_to,表格接受外键的责任。 所以Content有一个content_template_id。 而ContentTemplate不需要任何东西。 我可以随意指出。 完成。 Bug belongs_to状态会更合适(因为Bug应该采用外键)。 在语义上,他的例子是有道理的,但是我没有。 这只是一个铁轨的怪癖,在这种情况下,它看起来很奇怪,或者我不理解的东西/做错了吗?

如何用has_many关联在FactoryGirl中设置工厂

有人能告诉我,如果我只是在错误的方式进行安装? 我有以下有has_many.through关联的模型: class Listing < ActiveRecord::Base attr_accessible … has_many :listing_features has_many :features, :through => :listing_features validates_presence_of … … end class Feature < ActiveRecord::Base attr_accessible … validates_presence_of … validates_uniqueness_of … has_many :listing_features has_many :listings, :through => :listing_features end class ListingFeature < ActiveRecord::Base attr_accessible :feature_id, :listing_id belongs_to :feature belongs_to :listing end 我使用的是Rails 3.1.rc4,FactoryGirl 2.0.2,factory_girl_rails 1.1.0和rspec。 这里是我的基本rspec rspec完整性检查:listing工厂: […]

ActiveAdmin与has_many问题; 未定义的方法'new_record?'

我正在尝试为与Step具有has_many关系的食谱模型自定义ActiveAdmin表单。 class Recipe < ActiveRecord::Base has_many :steps end class Step < ActiveRecord::Base acts_as_list :scope => :recipe belongs_to :recipe end 我在我的ActiveAdmin文件中有以下关系: form do |f| f.has_many :steps do |ing_f| ing_f.inputs end end 我尝试加载表单时引发以下错误: 未定义的方法`new_record?' 为零:NilClass 我已经把它隔离到has_many方法,但我迷失了过去。 任何意见和帮助,将不胜感激!