2014-02-25 3 views
2

여러 특성 (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:setuprake 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를 심는 시도

+0

'제품'모델에서 유효성을 보여주십시오. – nathanvda

+0

@nathanvda CUSTOMER_TYPES = [ "Retailer", "Manufacturer"] 유효성 검사 : customer_type, 포함 : CUSTOMER_TYPES – Renegade

답변

7

모델이 저장되지 않는 것 같습니다. create 전화에서 오류를 무시합니다. 대신 Product.create!을 사용하고 작성에 실패하면 예외가 발생합니다.

+0

감사합니다. 이제 customer_type이 포함되지 않았다는 오류가 발생했습니다. 이것은 내 모델의 필수 입력란으로 CUSTOMER_TYPES 선택 목록으로 설정되었습니다. DB seed 파일의 선택 옵션 중 하나를 입력했지만 표시되지 않습니다. 내가 잘못하고있는 어떤 생각? – Renegade