views:

53

answers:

2

this is the code I have. It is a method for a contact.rb (Contact is a model):

  def event_delay event
    # find instance of contact_event
    puts "+++++++++++++++inside event_delay method"
    event_class = event.class.name
    event_id = event_class.foreign_key.to_sym

    #puts event_id
    contact_event_class = "Contact#{event_class}".constantize
    #puts contact_event_class

    contact_event = contact_event_class.first(:conditions => 
                                                {:contact_id => self.id, 
                                                event_id => event.id})
    #puts "inspect contact_event"
    #puts contact_event.inspect 
    if !contact_event.nil?
       puts "---- #{contact_event.title} not nill"
       puts contact_event.id
       date_sent = contact_event.date_sent
       target_send_date = self.date_entered + event.days
       puts "date_sent:"
       puts date_sent.to_date
       puts "target send date:"
       puts target_send_date

       return date_sent - target_send_date
    end                                           

  end

The goal is to return the difference in days between the time a date_sent to the time target_send_date. But I get the following error:

undefined method `-@' for Sun, 08 Aug 2010:Date
+3  A: 

Maybe both values are not dates? The - method is defined so that's why I'm thinking that you might not have two dates. Does this work in irb for you?

irb(main):001:0> require "date"
=> true
irb(main):002:0> Date.new(2010, 10, 20) - Date.new(2010, 9, 20)
=> Rational(30, 1)
irb(main):003:0>
Andy Gaskell
You mean run your code in irb? let me check real quick...as you can see my from output, I do a puts on the value and they *look* like dates....08/08/10 for example....
Angela
yep, get exactly what you've got....
Angela
I didn't know you were on heroku. We'll switch to `heroku console`. This also works on `heroku console` for me - `Date.today - "Sun, 08 Aug 2010".to_date`. I get the feeling that you either have a malformed date string or a nil value where you maybe aren't expecting one.
Andy Gaskell
yeah, messed up data that hadn't been checked for nil....thanks.
Angela
A: 

The @ in the error message is curious. I would suspect a typo such as date1 -@ date2 instead of date1 - @date2 somewhere in your code.

Mark Thomas