Ruby hashes are great and Ruby with DataMapper is even greater... This is regarding instantiating a DateTime property in Ruby using Hashes. It is involved with DataMapper.
I have a modal, User
that has a birthday that is stored as DateTime
class User
include DataMapper::Resource
property :id, Serial
# Some other properties
property :date_of_birth, DateTime
property :gender, Enum[:male, :female, :other], {
default: :other,
}
property :children, Integer
end
To populate the form I use some thing like this with HTML
<form method="post">
<input type="text" name="user[name]" id="user-name">
<!-- other fields -->
<select name="{what to use for year?}" id="user-birth-year>
<option value="1980">1980</option>
<!-- other options -->
</select>
<select name="{what to use for month?}" id="user-birth-month>
<option value="1">January</option>
<!-- other options -->
</select>
<!-- Other fields -->
</form>
In the register.rb
(route) I do some thing like this...
post '/auth/register' do
user = User.new(params['user'])
# Other stuff
end
As I understand, the has user has to kind of be similar to its fields. So how would the date_of_birth field be named to achieve this.
My assumption was to use some thing like this, but it doesn't seem to work.
:date_of_birth = {
:year => '2010'
:month => '11'
:date => '20'
}
Which would be given by names user[data_of_birth][year]
user[date_of_birth][month]
and user[date_of_birth][date]
for the select lists.