Thanks for the reply Ben. I think my question is more to do with DataMapper, because DataMapper requires the format to be a Date or DateTime object. My question is how I change what is effectively a string in the params hash into a date object in a neat way. Even if I used a date picker, I would assume that it sends some sort of string to the server rather than an actual Date object?
Hope that clarifies my question - is there a neat way of converting dates to Date objects or is there just some donkey work that needs doing before creating the resource? cheers, DAZ On Sunday, October 7, 2012 2:07:30 PM UTC+1, benlovell wrote: > > I think this question would be better served in whichever list pertains to > your chosen web framework (Sinatra I suspect?) but the simple answer is to > use one of the many available date pickers. > > http://trentrichardson.com/examples/timepicker/ > > Regards, > Ben > > Sent from my iPhone > > On 7 Oct 2012, at 11:48, DAZ <daz...@gmail.com <javascript:>> wrote: > > 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 datam...@googlegroups.com<javascript:> > . > To unsubscribe from this group, send email to > datamapper+...@googlegroups.com <javascript:>. > For more options, visit this group at > http://groups.google.com/group/datamapper?hl=en. > > -- 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/-/6zgiTuxv7zwJ. To post to this group, send email to datamapper@googlegroups.com. To unsubscribe from this group, send email to datamapper+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.