Created
September 7, 2012 22:36
Revisions
-
sfaxon created this gist
Sep 7, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ Post.class_eval do columns.select { |c| c.type == :datetime }.map { |c| c.name }.each do |date_time_field| class_eval <<-RUBY, __FILE__, __LINE__ + 1 def #{date_time_field}_date_picker read_attribute(:#{date_time_field}).to_s(:date_picker) end def #{date_time_field}_time_picker read_attribute(:#{date_time_field}).to_s(:time_picker) end def #{date_time_field}_date_picker=(date) # this needs to deal with timezone, and not rewrite the existing time fields write_attribute(:#{date_time_field}, DateTime.strptime(date, Time::DATE_FORMATS[:date_picker])) end RUBY end end