Skip to content

Instantly share code, notes, and snippets.

@dabonka
Created October 31, 2015 20:13
Show Gist options
  • Save dabonka/db246cb4da3c141f37cb to your computer and use it in GitHub Desktop.
Save dabonka/db246cb4da3c141f37cb to your computer and use it in GitHub Desktop.
\flashcards\app\models\card.rb
\flashcards\app\models\card.rb
============================
class Card < ActiveRecord::Base
def set_review_date
review_date = DateTime.now + 3.days
logger.debug "def set_review_date from debug"
logger.info "def set_review_date from info"
end
logger.debug "before_validation :set_review_date from debug"
logger.info "before_validation :set_review_date from info"
before_validation :set_review_date
validates :original_text, :translated_text, :review_date, presence: true
validates_with EqualValidator
end
class EqualValidator < ActiveModel::Validator
def validate(card)
Rails.logger.info "validates"
if ((card != nil) && (card.original_text != nil) && (card.translated_text != nil))
if card.original_text.downcase == card.translated_text.downcase
translated_text.errors[:base] << "The values of original text and translated text should be different"
end
end
end
end
==========================
ошибка:
ActiveRecord::RecordInvalid in CardsController#create
Validation failed: Review date can't be blank
Extracted source (around line #22):
20
21
22
23
24
25
@card = Card.new(cards_params)
@card.save!
redirect_to @card
end
Rails.root: /vagrant/flashcards
Application Trace | Framework Trace | Full Trace
app/controllers/cards_controller.rb:22:in `create'
Request
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"st8mVqRwdDBtWAXKja5d6WstW/A7MaJAokKpPfil9sY=",
"card"=>{"original_text"=>"123",
"translated_text"=>"321"},
"commit"=>"Save Card"}
Toggle session dump
Toggle env dump
Response
Headers:
None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment