Hello,
/* Insert usual disclaimer about being new to Rails and probably Ruby */
I have a form that updates a table of monitors, and, among other
fields, has monitor_start and monitor_end, both of which are
timestamps (using Postgres.)
On the form, I want the user to be able to, optionally, specify the
start of the monitoring, using the standard Rails date dropdowns,
and then a length for the monitoring: week, fortnight, month, 3
month, 6 months, year. That works fine.
Upon submission, I need to fix the monitor_end value to be a timestamp
instead of the length. My first try at it, I sent all the params
to a function which create a date from the monitor_start values then added
monitor_end to it and replaced monitor_end with the new timestamp.
This worked but made me feel dirty :)
So I decided to do this in the model with before_save as that felt
like the right way to handle it. Now on to my problem, which is
likely something stupid. I set a breakpoint in my called function,
set_monitor_end, so I could try out how create the timestamp. My
original function used the values from param: monitor_start(1i),
monitor_start(2i), monitor_start(3i) to create a new date and then
added the value from monitor_end to it. I don''t have those values
in the model, so I tried parsing monitor_start using Date. This
gets me an error about a private method, though:
irb(#<User_monitor:0x8c7802c>):026:0* self
=> #<User_monitor:0x8c7802c
@__bp_file="./script/../config/../app/models/user_monitor.rb",
@attributes={"updated_at"=>nil,
"interface_id"=>"247",
"type"=>"User_monitor",
"monitor_end"=>"14", "monitor_start"=>Tue
Oct 25 00:00:00 EDT 2005, "user_id"=>"1"}, @__bp_line=5,
@new_record=true, @errors=#<ActiveRecord::Errors:0x8c62808
@base=#<User_monitor:0x8c7802c ...>, @errors={}>>
irb(#<User_monitor:0x8c7802c>):027:0> Date.strptime(self.monitor_start)
NoMethodError: private method `sub!'' called for Tue Oct 25 00:00:00 EDT
2005:Time
from (druby://localhost:42531)
/usr/local/lib/ruby/1.8/date/format.rb:168:in `__strptime''
from (druby://localhost:42531)
/usr/local/lib/ruby/1.8/date/format.rb:54:in `scan''
from (druby://localhost:42531)
/usr/local/lib/ruby/1.8/date/format.rb:54:in `__strptime''
from (druby://localhost:42531)
/usr/local/lib/ruby/1.8/date/format.rb:83:in `__strptime''
from (druby://localhost:42531)
/usr/local/lib/ruby/1.8/date/format.rb:54:in `scan''
from (druby://localhost:42531)
/usr/local/lib/ruby/1.8/date/format.rb:54:in `__strptime''
from (druby://localhost:42531)
/usr/local/lib/ruby/1.8/date/format.rb:229:in `_strptime''
from (druby://localhost:42531) /usr/local/lib/ruby/1.8/date.rb:674:in
`strptime''
from (druby://localhost:42531) (irb):27:in `breakpoint''
from (druby://localhost:42531)
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/callbacks.rb:333:in
`breakpoint''
from (druby://localhost:42531)
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/callbacks.rb:333:in
`breakpoint''
from (druby://localhost:42531)
./script/../config/../app/models/user_monitor.rb:5:in `set_monitor_end''
from (druby://localhost:42531)
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/callbacks.rb:333:in
`send''
from (druby://localhost:42531)
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/callbacks.rb:333:in
`callback''
from (druby://localhost:42531)
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/callbacks.rb:330:in
`each''
from (druby://localhost:42531)
/usr/local/lib/ruby/gems/1.8/gems/activerecord-1.11.1/lib/active_record/callbacks.rb:330:in
`callback''
... 54 levels...
from /usr/local/lib/ruby/1.8/drb/drb.rb:1508:in `main_loop''
from /usr/local/lib/ruby/1.8/drb/drb.rb:1504:in `start''
from /usr/local/lib/ruby/1.8/drb/drb.rb:1504:in `main_loop''
from /usr/local/lib/ruby/1.8/drb/drb.rb:1371:in `run''
from /usr/local/lib/ruby/1.8/drb/drb.rb:1368:in `start''
from /usr/local/lib/ruby/1.8/drb/drb.rb:1368:in `run''
from /usr/local/lib/ruby/1.8/drb/drb.rb:1293:in `initialize''
from /usr/local/lib/ruby/1.8/drb/drb.rb:1549:in `new''
from /usr/local/lib/ruby/1.8/drb/drb.rb:1549:in `start_service''
from
/usr/local/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/breakpoint_client.rb:146
from
/usr/local/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/breakpoint_client.rb:145:in
`loop''
from
/usr/local/lib/ruby/gems/1.8/gems/rails-0.13.1/lib/breakpoint_client.rb:145
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__''
from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require''
from
/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.1.1/lib/active_support/dependencies.rb:200:in
`require''
from script/breakpointer:4irb(#<User_monitor:0x8c7802c>):028:0>
Like I said, it''s probably stupidity on my part, but how should I
go about doing this?
Thanks,
Denny Reiter
--
Denny Reiter
denny-wJvvXGulOwdAfugRpC6u6w@public.gmane.org
Secret hacker rule #11: hackers read manuals.