Forum: Ruby on Rails Use Time.zone.parse outside of Rails

48cfa8ad9f21bcf674af8474c33ea254?d=identicon&s=25 wam r. (wam_r)
on 2012-11-06 13:31
(Received via mailing list)
Hi guys,

I am trying to use an ActiveRecord function in a Ruby script, and I
can't
get it to work. I am using ActiceRecord 3.2.8.

> require 'active_support/all'
> Time.zone.parse("2012-10-20")
NoMethodError: undefined method `parse' for nil:NilClass
from (irb):2
from /Users/pjj/.rvm/rubies/ruby-1.9.2-p320/bin/irb:16:in `<main>'


Time.zone.parse works absolutely fine in a Rails console.

I am not sure what step I am missing. What is Rails doing to let us use
this function directly?

Thanks a lot
PJ
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2012-11-06 13:45
(Received via mailing list)
On Tue, Nov 6, 2012 at 4:30 AM, PierreW <wamrewam@googlemail.com> wrote:

>> require 'active_support/all'
>> Time.zone.parse("2012-10-20")
> NoMethodError: undefined method `parse' for nil:NilClass

> Time.zone.parse works absolutely fine in a Rails console.
>
> I am not sure what step I am missing. What is Rails doing to let us use this
> function directly?

Setting Time.zone to a value so it's not nil  :-)

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.