question about before_create

Denny Reiter
Wed, 26 Oct 2005 17:19:00 -0000

I''m trying to "fix" a record before it is inserted into a
table.
I have two attributes, monitor_start and monitor_end.  On some
forms, instead of the user specifying monitor_end, I want to let
them specify the length of the monitoring in days.  I''m putting
this value into monitor_end and then want to fix it using before_create.
My problem is when I try and access monitor_end it is nil instead
of the value.  If I insert a breakpoint and look at the object, the
value is there but I can''t seem to access it.  Is there a way for
me to pull this value out?

Is this the "right" way to do this, or should i just fix the value up
in
the controller before calling save?

Thanks,

Denny Reiter


irb(#<User_monitor:0x8dfc470>):007:0> self
=> #<User_monitor:0x8dfc470
@__bp_file="./script/../config/../app/models/user_monitor.rb",
@attributes={"updated_at"=>Wed Oct 26 13:10:50 EDT 2005,
"interface_id"=>"2",
"type"=>"User_monitor",
"monitor_end"=>"365", "monitor_start"=>Wed
Oct 26 00:00:00 EDT 2005, "user_id"=>"1"}, @__bp_line=5,
@new_record=true, @errors=#<ActiveRecord::Errors:0x8dee2d0
@base=#<User_monitor:0x8dfc470 ...>, @errors={}>>
irb(#<User_monitor:0x8dfc470>):008:0> self.monitor_end
=> nil
irb(#<User_monitor:0x8dfc470>):009:0>

--
Denny Reiter
denny-wJvvXGulOwdAfugRpC6u6w@public.gmane.org
                   It''s not a bug, it''s tradition!