여러 특성 (customer_type
, customer_name
, dept_type
등 ...)이있는 제품 모델이 있는데 일부 데이터를 시드하려고합니다.유효성 검사 오류 시드 레일 3 weeds.rb
나는 그때는 오류 메시지를 얻을 rake db:Seed
을 실행하지만로드 할 때 데이터의 내 응용 프로그램의 어떤 것도 존재하지 내가 파일을 저장 내 db/seeds.rb
파일
Product.create(customer_type:'Retailer', customer_name: 'Walmart', dept_type: 'Grocery')
에 다음습니까? 여기서 내가 뭘 잘못하고 있니?
또한 오류 메시지를 반환하지 않지만 데이터가로드되지 않을 때마다 rake db:setup
및 rake db:reset
을 시도했습니다. 내가 갈퀴 DB를 실행하면
업데이트 내가이
Product.create!(customer_type:'Retailer', customer_name: 'Walmart', dept_type: 'Grocery')
처럼 내 DB 씨앗 파일을 수정 : 내가 오류가 다시 "확인 실패 : 고객 유형이 목록에 포함되지 않는다"
검증와 내 제품 모델 파일은
class Product < ActiveRecord::Base
attr_accessible :customer_type
has_many :line_items
has_many :orders, through: :line_items
CUSTOMER_TYPES = ["Retailer", "Manufacturer"]
validates :customer_type, inclusion: CUSTOMER_TYPES
나는 고객 유형의 두 값의 소매 업체와 제조업체 행운과 DB를 심는 시도
'제품'모델에서 유효성을 보여주십시오. – nathanvda
@nathanvda CUSTOMER_TYPES = [ "Retailer", "Manufacturer"] 유효성 검사 : customer_type, 포함 : CUSTOMER_TYPES – Renegade