I am adding a function to check for 2 digit dates and change them into
4 digit before a Date.new has time to choke on it. My model is :
class Person < ActiveRecord::Base
belongs_to :household
def before_validation
# debugger
self.month_int = self.month.to_i
self.day_int = self.day.to_i
self.year_int = self.year.to_i
if (year_int > 0) && (month_int > 0) && (month_int
< 13) &&
(day_int > 0)&& (day_int < 32)
if (self.year_int < 100)
@compare = Date.new(2000+self.year_int,self.month_int,
self.day_int)
if (@compare > Date.today)
self.year_int = 1900+self.year_int
else
self.year_int = 2000+self.year_int
end
self.year = self.year_int.to_s
end
self.birthday = Date.new(self.year_int, self.month_int,
self.day_int)
else
errors.add("Date")
end
debugger
end
validates_inclusion_of :month_int, :in => 1..12,
:message => "should be between 1 and 12"
validates_inclusion_of :day_int, :in => 1..31,
:message => "should be between 1 and 31"
validates_numericality_of :year_int
validates_inclusion_of :sex, :in => %w{ M F },
:message => "should be ''M'' or
''m'' or ''F'' or ''f''"
validates_presence_of :sex, :month, :day, :year
validates_date :birthday, :before => Date.today+1, :after =>
''Jan 1
1900'', :before_message => ''Needs to be today or
before.'', :after_message => ''Needs to be after
1/1/1900.''
end
since I added the code that changes a model variable, I get 2
breakpoints from the 2 changes. This is not needed by my app and
causes a breakpoint that my user won''t know how to bypass. Please help
with removing this issue. I assume rails is error-checking my code and
having a fit about not telling the views that a field has changed..
Bob <bsm2th-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
On 11 May 2010 21:53, Bob Smith <bsm2th-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I am adding a function to check for 2 digit dates and change them into > 4 digit before a Date.new has time to choke on it. My model is : > > class Person < ActiveRecord::Base > belongs_to :household > > def before_validation > # debugger > self.month_int = self.month.to_i > self.day_int = self.day.to_i > self.year_int = self.year.to_i > if (year_int > 0) && (month_int > 0) && (month_int < 13) && > (day_int > 0)&& (day_int < 32) > if (self.year_int < 100) > @compare = Date.new(2000+self.year_int,self.month_int, > self.day_int) > if (@compare > Date.today) > self.year_int = 1900+self.year_int > else > self.year_int = 2000+self.year_int > end > self.year = self.year_int.to_s > end > self.birthday = Date.new(self.year_int, self.month_int, > self.day_int) > else > errors.add("Date") > end > debugger > end > > validates_inclusion_of :month_int, :in => 1..12, > :message => "should be between 1 and 12" > validates_inclusion_of :day_int, :in => 1..31, > :message => "should be between 1 and 31" > validates_numericality_of :year_int > validates_inclusion_of :sex, :in => %w{ M F }, > :message => "should be ''M'' or ''m'' or ''F'' or ''f''" > validates_presence_of :sex, :month, :day, :year > validates_date :birthday, :before => Date.today+1, :after => ''Jan 1 > 1900'', :before_message => ''Needs to be today or > before.'', :after_message => ''Needs to be after 1/1/1900.'' > > > end > > > since I added the code that changes a model variable, I get 2 > breakpoints from the 2 changes. This is not needed by my app and > causes a breakpoint that my user won''t know how to bypass. Please help > with removing this issue. I assume rails is error-checking my code and > having a fit about not telling the views that a field has changed..I am confused about exactly what is the problem that you are having. Is it that the code is stopping at the debugger statement in your code? If so just remove the debugger statement. If this is not the problem please be more explicit about what is happening. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
It acts like I set a breakpoint, but I haven''t. Not sure why, but this problem vanished last night.. Bob On May 11, 5:18 pm, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> On 11 May 2010 21:53, Bob Smith <bsm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I am adding a function to check for 2 digit dates and change them into > > 4 digit before a Date.new has time to choke on it. My model is : > > > class Person < ActiveRecord::Base > > belongs_to :household > > > def before_validation > > # debugger > > self.month_int = self.month.to_i > > self.day_int = self.day.to_i > > self.year_int = self.year.to_i > > if (year_int > 0) && (month_int > 0) && (month_int < 13) && > > (day_int > 0)&& (day_int < 32) > > if (self.year_int < 100) > > @compare = Date.new(2000+self.year_int,self.month_int, > > self.day_int) > > if (@compare > Date.today) > > self.year_int = 1900+self.year_int > > else > > self.year_int = 2000+self.year_int > > end > > self.year = self.year_int.to_s > > end > > self.birthday = Date.new(self.year_int, self.month_int, > > self.day_int) > > else > > errors.add("Date") > > end > > debugger > > end > > > validates_inclusion_of :month_int, :in => 1..12, > > :message => "should be between 1 and 12" > > validates_inclusion_of :day_int, :in => 1..31, > > :message => "should be between 1 and 31" > > validates_numericality_of :year_int > > validates_inclusion_of :sex, :in => %w{ M F }, > > :message => "should be ''M'' or ''m'' or ''F'' or ''f''" > > validates_presence_of :sex, :month, :day, :year > > validates_date :birthday, :before => Date.today+1, :after => ''Jan 1 > > 1900'', :before_message => ''Needs to be today or > > before.'', :after_message => ''Needs to be after 1/1/1900.'' > > > end > > > since I added the code that changes a model variable, I get 2 > > breakpoints from the 2 changes. This is not needed by my app and > > causes a breakpoint that my user won''t know how to bypass. Please help > > with removing this issue. I assume rails is error-checking my code and > > having a fit about not telling the views that a field has changed.. > > I am confused about exactly what is the problem that you are having. > Is it that the code is stopping at the debugger statement in your > code? If so just remove the debugger statement. > > If this is not the problem please be more explicit about what is happening. > > Colin > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
[Please quote when replying.] Bob Smith wrote:> It acts like I set a breakpoint, but I haven''t. Not sure why, but this > problem vanished last night..Perhaps the class was cached (which Rails does automatically in production) and the cached version included the breakpoints? Then if you restarted the server, it would have reloaded the class.> > BobBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.