0
한 모델에서 동일한 모델에 속한 두 모델에 대한 새 레코드를 만들어야합니다. 레일즈에서 동시에 두 모델의 has_one에 새로운 레코드를 생성하는 방법은 무엇입니까?
이
내가 제출할 때이 그럼 난 항상이 줄에이 오류undefined method `build_promotion_thai' for #<PromotionEng:0x007f9fdbcb0250> Did you mean? build_promotion
에게있어 양식 내 컨트롤러 방법
def create
promotion = Promotion.new
promotion.build_promotion_eng(promotion_eng_params).build_promotion_thai(promotion_thai_params)
if promotion.save
flash[:success] = 'Success Created Promotion'
redirect_to admins_promotions_path
else
errors_message = promotion.errors.full_messages.join(', ')
redirect_to admins_promotion_new_path, :flash => { :error => errors_message }
end
end
내 모델
class Promotion < ApplicationRecord
has_one :promotion_thai ,dependent: :destroy
has_one :promotion_eng ,dependent: :destroy
end
class PromotionThai < ApplicationRecord
belongs_to :promotion
mount_uploader :long_banner, PromotionImageUploader
mount_uploader :square_banner, PromotionImageUploader
mount_uploader :details_image, PromotionImageUploader
validates :promotion_id, presence: true
validates :title, presence: true
validates :description, presence: true
#validates :long_banner, presence: true
#validates :square_banner, presence: true
end
class PromotionEng < ApplicationRecord
belongs_to :promotion
mount_uploader :long_banner, PromotionImageUploader
mount_uploader :square_banner, PromotionImageUploader
mount_uploader :details_image, PromotionImageUploader
validates :promotion_id, presence: true
validates :title, presence: true
validates :description, presence: true
validates :long_banner, presence: true
validates :square_banner, presence: true
end
입니다
promotion.build_promotion_eng(promotion_eng_params).build_promotion_thai(promotion_thai_params)
어떻게 이러한 문제를 해결할 수 있습니까?
감사합니다.
오 이런 작품은 훌륭하지만 유효성 검사가 더 이상 작동하지 않는 것 같습니다. 어떻게 작동시키는 지 알고 계십니까? – user3403614
어떤 인증이 필요합니까? 프로모션 모델에 대한 유효성 검사가 없습니다. –