Rails 4 ActiveSupport::Concern
//date_normalizer.rb
module Concerns
module DateNormalizer
extend ActiveSupport::Concern
included do |base|
base.after_validation :normalize_date
end
def normalize_date
self.created_at = return_DateTime(self.created_at)
end
end
end
File model / entry.rb
class Entry < ActiveRecord::Base
include Concerns::DateNormalizer
belongs_to :patient
validates :text, presence: true
end
File models / post.rb
class Post < ActiveRecord::Base
include Concerns::DateNormalizer
end
Note. I renamed for you normalizeDatetonormalize_date
source
share