Forum: Ruby on Rails Date magic?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jørn �lmheim (Guest)
on 2006-03-31 15:49
(Received via mailing list)
Hi.

When I read Dave and Davids excellent book "Agile Web D. with
Rails" the first time, I was particularly impressed with the following
statement:
1.day.from_now

It was used in a test class to set the date of tomorrow dynamically.
Since
it was enclosed in in ERb tags, I assumed this was a normal ruby
statement,
but when I tried it in my irb, i get the following error:
irb(main):007:0> 1.day.from_now
NoMethodError: undefined method `day' for 1:Fixnum
        from (irb):7
irb(main):008:0>

I would be abliged if someone could explain to me how this works in ERb
and
not in standard ruby? Have I missed something fundamental here?

Best regards,
Jørn �lmheim
www: http://www.olmheim.com
blog: http://blog.olmheim.com
Mikkel B. (Guest)
on 2006-03-31 16:04
(Received via mailing list)
Its an extension f the Time class

http://api.rubyonrails.org/classes/ActiveSupport/C...
Time.html

So, its not ruby, its rails...


On Friday, March 31, 2006, at 1:48 PM, Jørn Ølmheim wrote:
>irb(main):007:0> 1.day.from_now
>blog: http://blog.olmheim.com
>
>
>_______________________________________________
>Rails mailing list
>removed_email_address@domain.invalid
>http://lists.rubyonrails.org/mailman/listinfo/rails
>


Mikkel B.

www.strongside.dk    - Football Portal(DK)
ting.minline.dk      - Buy Old Stuff!(DK)
Jonathan V. (Guest)
on 2006-03-31 16:50
(Received via mailing list)
Indeed. You need to use script/console instead of a plain ruby shell.

On 31 Mar 2006 12:02:10 -0000, Mikkel B. <
Julian 'Julik' Tarkhanov (Guest)
on 2006-04-01 20:15
(Received via mailing list)
On 31-mrt-2006, at 13:48, Jørn Ølmheim wrote:

> the following error:
> irb(main):007:0> 1.day.from_now
> NoMethodError: undefined method `day' for 1:Fixnum
>         from (irb):7
> irb(main):008:0>
>
> I would be abliged if someone could explain to me how this works in
> ERb and not in standard ruby? Have I missed something fundamental
> here?
>

days_from_now etc. is a part of ActiveSupport
Jeff C. (Guest)
on 2006-04-01 22:36
Heh, in a thread last week about Rails driving development of Ruby,
somebody asked how long it would be til someone mistook Rails'
core-extensions for Ruby :)

Jeff

Julian 'Julik' Tarkhanov wrote:
> On 31-mrt-2006, at 13:48, J�rn �lmheim wrote:
>
>> the following error:
>> irb(main):007:0> 1.day.from_now
>> NoMethodError: undefined method `day' for 1:Fixnum
>>         from (irb):7
>> irb(main):008:0>
>>
>> I would be abliged if someone could explain to me how this works in
>> ERb and not in standard ruby? Have I missed something fundamental
>> here?
>>
>
> days_from_now etc. is a part of ActiveSupport
This topic is locked and can not be replied to.