Skip to content

Instantly share code, notes, and snippets.

View jacobwalkr's full-sized avatar

Jacob Walker jacobwalkr

View GitHub Profile
@jacobwalkr
jacobwalkr / date_time_splittable.rb
Last active February 9, 2021 17:18
ActiveRecord concern for accessing the date and time parts of a datetime attribute separately
module DateTimeSplittable
extend ActiveSupport::Concern
included do
def self.split_date_time(*attributes)
attributes.each do |attribute|
if self.type_for_attribute(attribute).type != :datetime
raise ArgumentError.new("#{attribute} is not of type datetime")
end