K
keldog
Hello all...
Wondering if someone can help me out with a date issue.
My environment:
ruby: 1.9.2p0
rails: 3.0.3
mac os x
My issue:
From what I've been reading, the date format has been changed in
1.9.2. So, saving dates in the "mm/dd/yyy" format has been an issue
since 1.9.2 is saving as "dd/mm/yyyy"
I have a jQuery plugin that uses the date picker and displays in the
format of "mm/dd/yyyy" However, sometimes the date saves and other
times it doesn't because of ruby expecting the changed format (mm/dd/
yyyy). For example:
3/1/2011 saves as 1/3/2011
3/13/2011 doesn't save (returns "")
I have the following code in my model to inspect the date (in my case,
start_date of a course):
Tried the following:
1) In the /config/initializers directory, created a date_format.rb to
change the date. However, that's for display purposes only (I
believe).
2) In the fix_dates function above, I added:
self.start_date = Date.strptime(self.start_date.to_s,'%m/%d/%Y').to_s
But this isn't valid since ruby will set the date to an empty string
before executing this code.
I think there is a really simple solution for this work around, but
I've failed to find one thus far. Any help is greatly appreciated!
-K
Wondering if someone can help me out with a date issue.
My environment:
ruby: 1.9.2p0
rails: 3.0.3
mac os x
My issue:
From what I've been reading, the date format has been changed in
1.9.2. So, saving dates in the "mm/dd/yyy" format has been an issue
since 1.9.2 is saving as "dd/mm/yyyy"
I have a jQuery plugin that uses the date picker and displays in the
format of "mm/dd/yyyy" However, sometimes the date saves and other
times it doesn't because of ruby expecting the changed format (mm/dd/
yyyy). For example:
3/1/2011 saves as 1/3/2011
3/13/2011 doesn't save (returns "")
I have the following code in my model to inspect the date (in my case,
start_date of a course):
Code:
before_filter :fix_dates
private
def fix_dates
raise self.start_date.to_s.inspect
end
Tried the following:
1) In the /config/initializers directory, created a date_format.rb to
change the date. However, that's for display purposes only (I
believe).
2) In the fix_dates function above, I added:
self.start_date = Date.strptime(self.start_date.to_s,'%m/%d/%Y').to_s
But this isn't valid since ruby will set the date to an empty string
before executing this code.
I think there is a really simple solution for this work around, but
I've failed to find one thus far. Any help is greatly appreciated!
-K