Look at your development.log (or the console window if you've got your
server running there). You can see that the parameter from is actually
a hash {'(1i)' => '1953', '(2i)' => '5', '(3i)' => 4}, ie. the date
components are passed separately. If instead of using date_select you
use select_date, you'll even get friendly names in there ({'year' =>
1953, 'month' => 5, 'day' => 3}). All you need to do is put those back
together into a date. Somehow this feels like the most frequently
asked question this week, so the other threads about date_select &
select_date might also help you.
Totally agree Fred, I had a hunt around in the forums and there were
masses of posts on the subject but no clear resolution.
I thought it best to post as much info as I could to try to resolve
this, glad about the response.
I tried using select_date but couldn't get it working how i wanted. I
did find a post suggesting passing the param into a date object, thanks
Ilan for your solution.
ugh... everytime i tried using that i got a 'wrong number of arguments'
error
wrote a function to split the hash up and put it back together as a good
date...
def convert_date(obj)
@a = ''
@b = ''
@c = ''
for @d in params[:reg_from]
if @d.to_s.index('(1i)') : @a = @d.to_s[4,4] end
if @d.to_s.index('(2i)') : @b = @d.to_s[4,2] end
if @d.to_s.index('(3i)') : @c = @d.to_s[4,2] end
end
return "#{@a}-#{@b}-#{@c}"
end
...not the best way but gets results, any advances on this solution?
for @d in obj
if @d.to_s.index('(1i)') : @a = @d.to_s[4,4] end
if @d.to_s.index('(2i)') : @b = @d.to_s[4,2] end
if @d.to_s.index('(3i)') : @c = @d.to_s[4,2] end
end
There's easier: Time.mktime(params[:somedate]['(1i)'], params[:somedate]['(2i)'], params[:somedate]['(3i)']) (or use Date::civil instead of Time.mktime if you want an instance of date rather than time).
Thanks Fred, I tried hunting around for some extra info and examples for
converting a string to a date or time but couldn't find it (nothing in
the agile & programming books), appreciate this solution.
Frederick,
If this is such a commonly asked question then why doesn't someone
write an easy to follow example of taking a date from user input on a
non(form_for) view and then load it into the model.date_field.
I swear I've looked at countless examples on the internet and no one
takes it home.
Could someone be a prince and make this happen?
Kathleen
Frederick,
If this is such a commonly asked question then why doesn't someone
write an easy to follow example of taking a date from user input on a
non(form_for) view and then load it into the model.date_field.
I swear I've looked at countless examples on the internet and no one
takes it home.
Looks like John did just that I must admit I'm a bit surprised: it
shouldn't be that hard to figure out, especially compared to a lo of
the conceptually much harder things in ruby and/or rails.