--
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.
To unsubscribe from this group, send email to datamapper+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
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?
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/6zgiTuxv7zwJ.
Hi Ben,Thanks for the reply. This is what I thought was the case, but I just wondered if there were any nice DM methods that I didn't know about that parsed strings in a certain format, ready to insert into the database as a Date object.I've found that the jQuery datepicker gives the date in this format 10/09/2012, so I have added the following method to the Song class to change it into a Date object:def released_on=datedates = date.split('/').map{ |s| s.to_i }super(Date.new(dates[2],dates[0],dates[1]))end
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/jKlzyXpXcVMJ.
I'd suggest:
def released_on=date
super(Date.parse(date).iso8601)
end
Hi Daz,
On 9 October 2012 20:58, DAZ <daz...@gmail.com> wrote:Hi Ben,Thanks for the reply. This is what I thought was the case, but I just wondered if there were any nice DM methods that I didn't know about that parsed strings in a certain format, ready to insert into the database as a Date object.I've found that the jQuery datepicker gives the date in this format 10/09/2012, so I have added the following method to the Song class to change it into a Date object:def released_on=datedates = date.split('/').map{ |s| s.to_i }super(Date.new(dates[2],dates[0],dates[1]))end
Thanks for the reply Ben,I'd suggest:
def released_on=date
super(Date.parse(date).iso8601)
endthat certainly looks more elegant, but I get an 'invalid date' argument error for that if I try to enter the date in the format "10/09/2012", any ideas?
To view this discussion on the web visit https://groups.google.com/d/msg/datamapper/-/PdSYABOhqw8J.