diff --git a/lib/formtastic-separate_html5_date_and_time.rb b/lib/formtastic-separate_html5_date_and_time.rb
index 797b6f6..ef5c258 100644
--- a/lib/formtastic-separate_html5_date_and_time.rb
+++ b/lib/formtastic-separate_html5_date_and_time.rb
@@ -7,6 +7,10 @@ module Formtastic
require 'formtastic'
require 'formtastic-separate_html5_date_and_time/formtastic'
+ if defined?(ActiveRecord::Base)
+ require 'formtastic-separate_html5_date_and_time/active_record'
+ end
+
if defined?(Mongoid::Document)
require 'formtastic-separate_html5_date_and_time/mongoid'
end
diff --git a/lib/formtastic-separate_html5_date_and_time/active_record.rb b/lib/formtastic-separate_html5_date_and_time/active_record.rb
new file mode 100644
index 0000000..443a10e
--- /dev/null
+++ b/lib/formtastic-separate_html5_date_and_time/active_record.rb
@@ -0,0 +1,15 @@
+require 'formtastic-separate_html5_date_and_time/processor'
+
+module ActiveRecord
+ module ProcessSeparateDateAndTimePickerInputs
+ def assign_multiparameter_attributes(attrs)
+ Formtastic::SeparateDateAndTimePickerInput::Processor.process(attrs).each do |attribute, value|
+ public_send("#{attribute}=", value)
+ end
+ end
+
+ def update_attributes(attrs = nil)
+ super Formtastic::SeparateDateAndTimePickerInput::Processor.process(attrs)
+ end
+ end
+end
diff --git a/lib/formtastic-separate_html5_date_and_time/mongoid.rb b/lib/formtastic-separate_html5_date_and_time/mongoid.rb
index 1033271..08aa556 100644
--- a/lib/formtastic-separate_html5_date_and_time/mongoid.rb
+++ b/lib/formtastic-separate_html5_date_and_time/mongoid.rb
@@ -1,27 +1,10 @@
require 'mongoid'
+require 'formtastic-separate_html5_date_and_time/processor'
module Mongoid
module ProcessSeparateDateAndTimePickerInputs
def process_attributes(attrs = nil, role = :default, guard_protected_attributes = true)
- if attrs
- datetime_attrs = {}
-
- attrs.each do |key, value|
- if attr = key[/\A(.*)\((date|time)\)\Z/, 1]
- datetime_attrs[attr] ||= {}
- datetime_attrs[attr][key] = value
- end
- end
-
- datetime_attrs.each do |attr, values|
- attrs[attr] = values["#{attr}(date)"] + ' ' + values["#{attr}(time)"]
-
- attrs.delete("#{attr}(date)")
- attrs.delete("#{attr}(time)")
- end
- end
-
- super(attrs, role, guard_protected_attributes)
+ super Formtastic::SeparateDateAndTimePickerInput::Processor.process(attrs), role, guard_protected_attributes
end
end
end
diff --git a/lib/formtastic-separate_html5_date_and_time/processor.rb b/lib/formtastic-separate_html5_date_and_time/processor.rb
new file mode 100644
index 0000000..1a39680
--- /dev/null
+++ b/lib/formtastic-separate_html5_date_and_time/processor.rb
@@ -0,0 +1,29 @@
+module Formtastic
+ module SeparateDateAndTimePickerInput
+ class Processor
+ def self.process(attrs)
+ if attrs
+ attrs = Hash[attrs.dup]
+
+ datetime_attrs = {}
+
+ attrs.each do |key, value|
+ if attr = key[/\A(.*)\((date|time)\)\Z/, 1]
+ datetime_attrs[attr] ||= {}
+ datetime_attrs[attr][key] = value
+ end
+ end
+
+ datetime_attrs.each do |attr, values|
+ attrs[attr] = values["#{attr}(date)"] + ' ' + values["#{attr}(time)"]
+
+ attrs.delete("#{attr}(date)")
+ attrs.delete("#{attr}(time)")
+ end
+ end
+
+ attrs
+ end
+ end
+ end
+end