I have a shipment model with a method called returnable?
If a shipment has been delivered, it figures out what the last
returnable date is, delivery date + 14 days.
In Shipment Model
def returnable?
if last_return_date.nil?
return "Yes"
else
n = Time.now.to_i.abs.round
d = last_return_date.to_i.abs.round
if d >= n
return "Yes"
else
return nil
end
end
end
This works great on the intials edit view, but if the form is submitted
and there is a validation error, it gives the following error message:
NoMethodError in Shipments#update
undefined method `to_i'' for #<Date: 4910233/2,0,2299161>
Just wondering what''s up?
Both the update action and edit action grab the @shipment instance var
the same way, so this should totally work.
If I''m just a noob over complicating the "is this date greater
than this
date" thing and there''s a better way to write that, please feel
free to
correct me.
Any help is appreciated.
Thanks,
Dave
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Dave Coleman
2007-May-22 22:57 UTC
Re: works on intial show, but not after validation error
On the writing this less complicated front, I think I''ve got a better
version:
def returnable?
is_one = last_return_date <=> Time.now
if is_one >= 1
return "Yes"
else
return nil
end
end
Seems when my form submits and there''s a validation error, my fields of
type Time get transformed to type Date, so the to_i wasn''t available as
a method.
no clue why that is...
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
David Dumaresq
2007-May-23 22:47 UTC
Re: works on intial show, but not after validation error
I''m thinking you''ve not got a valid shipment object when you
recover from
the validation error.
Can you post your controller code?
Regards,
Dave
_______________________________
Information and Educational Technology
Kwantlen University College - 604-599-2120
"So powerful is the light of unity that it can illuminate the whole
earth." --Bahá''u''lláh
Dave Coleman <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
Sent by: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
22-05-2007 03:57 PM
Please respond to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
cc
Subject
[Rails] Re: works on intial show, but not after validation error
On the writing this less complicated front, I think I''ve got a better
version:
def returnable?
is_one = last_return_date <=> Time.now
if is_one >= 1
return "Yes"
else
return nil
end
end
Seems when my form submits and there''s a validation error, my fields of
type Time get transformed to type Date, so the to_i wasn''t available as
a method.
no clue why that is...
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Dave Coleman
2007-May-24 00:45 UTC
Re: works on intial show, but not after validation error
Hi Dave, I figured this one out. In my database, the date fields were of type datetime. However, when I displayed them in the form I was only showing mm/dd/yyy via strftime. So what was a Time object got turned into a Date object if a validation error occurred. Since the datetime field only had the date in it anyway, I just changed it''s type, changed all my Time.now''s to Date.today''s and it''s all fixed. Thanks for your help, Dave C -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---