3
내가 4 개 중첩 평가와 공장 심사를 만들 필요가
class Rating < ActiveRecord::Base
attr_accessible :type_id, :value
belongs_to :review
class Review < ActiveRecord::Base
attr_accessible :name, :description, :user_id, :relationship_type_id, :ratings_attributes
belongs_to :facility
has_many :ratings
accepts_nested_attributes_for :ratings, limit: Rating::RATE.count
는, 테스트 검토 확인을 위해 그것은`모델을 가지고,하지만 난 어떤 생각을 가지고 있겠지 내 공장 : 컨트롤러에서
factory :review do
facility
sequence(:name) { |n| "Name of review #{n}" }
sequence(:description) { |n| "asdasdasdasdasdasd #{n}" }
user_id 1
relationship_type_id 1
end
factory :rating do
type_id 2
value 3
review
factory :requred_rating do
type_id 1
end
end
내가 중첩 된 attrs에와 초기화 검토를 위해 쓰고 있어요 :
@review = Review.new
Rating::RATE.each do |rate|
@review.ratings.build(type_id: rate[1])
end
및 평가와 새로운 검토를 만드는 :
@review = @facility.reviews.build(params[:review])
if @review.save
모든 작업이 좋은,하지만 난 그게
제발 도와주세요 테스트해야합니다.
은 당신이 공유해야 내 문제 –
의 해결책을 발견했다. .. – hellion