views:

15

answers:

1

I need to pass a variable to my view with Time.now + @seconds in time format (i.e. 12pm + 3600 seconds = 1:00pm, which goes to the view).

Time.now + @seconds #seconds is a fixnum

doesn't work because "Time can't be coerced into Fixnum". How then can I generate this simple result?

+2  A: 

Don't barbeque me if this is wrong now but back when I was doing Rails you would just say Time.now + @seconds.seconds . Also @seconds.seconds.from_now

Chuck Vose
Hi Chuck, that doesn't seem to work because @seconds is just a fixnum like... 25, so Rails doesn't recognize 'from' or 'seconds' in context of a fixnum. I just need to add that fixnum to Time.now.
sscirrus
The second should work for you. I've updated the original post. Tested with Rails 2.3.5 via the script/console. You _do_ have to be in a Rails environment to use .seconds or .days or .hours.
Chuck Vose
Also, I messed up the syntax of from, it should have been from_now. from_now is an addition to Time and seconds is an addition to Fixnum within Rails
Chuck Vose
Rails monkeypatches Fixnums to add methods like #seconds and #days for easier time-related logic.
Raphomet
http://docs.huihoo.com/api/ruby-on-rails/classes/ActiveSupport/CoreExtensions/Numeric/Time.html
Raphomet