내 모델은 다음과 같습니다 공상 아무것도 확인하지 않습니다레일 모델이 유효 보이지만,
# Table name: invoices
#
# id :integer not null, primary key
# total :float
# discount :float
# description :text
# created_at :datetime not null
# updated_at :datetime not null
# company_id :integer
# secret :string(255)
# address_id :integer
# price_per_credit :float
# paid :boolean
내가 서버 및 레일 콘솔에서 모두이의 인스턴스를 생성 할 수 있습니다, 이러한 경우는 경우에 true를 돌려줍니다 나는 그들에게 .valid?
라고 부른다. (나는 테스트 목적으로 모든 검증을 끈다.)
1.9.3p194 :001 > i = Invoice.new
=> #<Invoice id: nil, total: nil, discount: nil, description: nil, created_at: nil, updated_at: nil, company_id: nil, secret: nil, address_id: nil, price_per_credit: nil, paid: nil>
1.9.3p194 :002 > i.valid?
=> true
그러나 어떤 이유로 이러한 인스턴스를 데이터베이스에 저장할 수 없습니다.
1.9.3p194 :003 > i.save
(0.3ms) begin transaction
(0.1ms) rollback transaction
=> false
로컬로 로컬로 sqlite를 사용하고 있습니다. 프로덕션 서버는 MySQL을 실행하지만 모두이 동작을 표시합니다. 나는 이것을 디버깅하기 위해 무엇을해야할지 잘 모르겠다. 나는 db:migrate
를 실행했고, 나의 보석은 최신이다. 어떻게 내가 이걸 불면 해?
'저장!'을 시도해보십시오. 아마도 당신은 이런 식으로 더 많은 정보를 얻을 것입니다. – jdoe
네, 그게 많은 도움이되었습니다. ActiveRecord :: RecordNotSaved : ActiveRecord :: RecordNotSaved'를 포함하여 더 많은 결과물을 얻었습니다. 그것은 큰 힌트였습니다. 구글이 나를 이끌었습니다 : http://apidock.com/rails/ActiveRecord/RecordNotSaved. 내 before_create 필터 중 하나는'invoice.paid'를 false로 설정했지만'false'도 반환하여 저장 프로 세스가 중단되었습니다. 단순히 메소드에'nil '을 추가하면 문제가 해결됩니다. –