cgriego/active_attr — Issue #83: Date typecasting issue when using Rails forms
Author: zlw
Created: 2012-03-07 02:37:14+00:00
State: open

simple_form (I think formtastic and raw Rails forms) are sending date in format:

```ruby
{ 'birthday(1i)' => 1992, 'birthday(2i)' => 10, 'birthday(3i)' => 14 }
```
active_attr can't handle this, even when using Date typecasting.

quick and dirty hack for that:

```ruby
class Form::Registration
include ActiveAttr::Model

attribute :birthday, type: Date

def initialize(*args)
if args.present?
attrs = args.extract_options!
new_attrs = attrs.merge({ birthday: parse_date(:birthday, attrs) })
super(new_attrs)
end
end

private

def parse_date(name, attrs)
Date.new(attrs[:"#{name}(1i)].to_i, attrs[:#{name}{2i)"].to_i, attrs[:"#{name}(3i)"].to_i
end
end
```