I have a Song class that looks like this:
class Song
include DataMapper::Resource
property :id, Serial
property :title, String
property :lyrics, Text
property :length, Integer
property :released_on, Date
end
Here's my form for creating it:
<form action="/songs" method="POST">
<input id="title" name="song[title]" type="text" />
<input id="length" name="song[length]" type="number" />
<input id="day" max="31" min="1" name="day" type="number" />
<input id="month" max="12" min="1" name="month" type="number" />
<input id="year" max="1998" min="1940" name="year" type="number" />
<textarea id="lyrics" name="song[lyrics]"></textarea>
<input type="submit" value="Save Song" />
</form>
I want to be able to create a new song resource by using
song = Song.create(params[:song])
The problem I'm having is with the released_on property, since it needs to
be a Date object.
At the moment, I am doing this:
date = Date.new(params[:year].to_i,params[:month].to_i,params[:day].to_i)
song = Song.create(params[:song].merge(released_on: date))
Does anybody know any nicer ways of entering a date into a form and being
able to simply call Song.create(params[:song]) without having to manipulate
the form parameters first?
cheers,
DAZ
--
You received this message because you are subscribed to the Google Groups
"DataMapper" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/datamapper/-/OOhRt2vQKNEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/datamapper?hl=en.