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.
A53986fe297d6e1dd1d97771b9588f71?d=identicon&s=25 Jørn �lmheim (Guest)
on 2006-03-31 13:49
(Received via mailing list)
Hi.

When I read Dave and Davids excellent book "Agile Web Development 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
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Mikkel Bruun (Guest)
on 2006-03-31 14: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
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
>


Mikkel Bruun

www.strongside.dk    - Football Portal(DK)
ting.minline.dk      - Buy Old Stuff!(DK)
631d1677786f0725da6ccee46043686e?d=identicon&s=25 Jonathan Viney (Guest)
on 2006-03-31 14: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 Bruun <
A2b2f4ee23989dc68529baef9cbddcd6?d=identicon&s=25 Julian 'Julik' Tarkhanov (Guest)
on 2006-04-01 18: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
59ea1b450935b9d70abfec4186b7a4d5?d=identicon&s=25 Jeff Coleman (progressions)
on 2006-04-01 20: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.