Ruby on rails 3 获取mongoid<-&燃气轮机;制造不起作用
我有个问题要问警察 “has_和_属于_many”和“accept_nested_attributes_for” 在制造和制造方面 我有一个可以提供多种服务的地点Ruby on rails 3 获取mongoid<-&燃气轮机;制造不起作用,ruby-on-rails-3,mongoid3,fabrication-gem,Ruby On Rails 3,Mongoid3,Fabrication Gem,我有个问题要问警察 “has_和_属于_many”和“accept_nested_attributes_for” 在制造和制造方面 我有一个可以提供多种服务的地点 class Location include Mongoid::Document field :name field :service has_and_belongs_to_many :services, inverse_of: :locations, autosave: true, dependent: :del
class Location
include Mongoid::Document
field :name
field :service
has_and_belongs_to_many :services, inverse_of: :locations, autosave: true, dependent: :delete
accepts_nested_attributes_for :services
attr_accessible :services, :name
class Service
include Mongoid::Document
field :name, type: String
has_and_belongs_to_many :locations, inverse_of: :services, autosave: true
accepts_nested_attributes_for :locations
attr_accessible :name, :icon, :description
在我的伪造文件上我有这个
Fabricator(:service) do
initialize_with { Location.produce(:location) }
name "Service Name"
description "Lorem ipsum est lauda en radios"
location
end
Fabricator(:location) do
name "Special Club"
service
end
在这种情况下,我的rspec挂断
是否有人可以提供一个使用mongoid和制作gem的*accept_nested_attributes*和/或*has_和\u belies_to_many*的工作示例(mongoid的“开箱即用”功能)
有什么建议吗
我正在使用mongoid3,这一切都取决于您如何使用制造 测试控制器的嵌套参数是一个痛苦的世界,您需要手工制作一些参数散列 对于型号,您应该尝试以下方法:
Fabricator(:service) do
name "Service Name"
description "Lorem ipsum est lauda en radios"
locations {[Fabricate.build(:location)]}
end
Fabricator(:location) do
name "Special Club"
service
end
你的关系可能不需要
:倒数的。这一切都取决于你如何使用编造
测试控制器的嵌套参数是一个痛苦的世界,您需要手工制作一些参数散列
对于型号,您应该尝试以下方法:
Fabricator(:service) do
name "Service Name"
description "Lorem ipsum est lauda en radios"
locations {[Fabricate.build(:location)]}
end
Fabricator(:location) do
name "Special Club"
service
end
你的关系可能不需要:反向的。谢谢Tsagadai,周末后再试一次!谢谢Tsagadai,周末后再试一次!