Forum: Ruby on Rails how to include activesupport in a ruby script???

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.
rph (Guest)
on 2007-02-26 01:35
I have a ruby script (not in a rails app) that pulls in delicious data
from their API, and then I read that data out of a file.  I'm having
trouble formatting the date coming back from delicious.

I'd like to use '.to_date' as that works fine from within the rails app,
but I don't know how to access (or require) the activesupport gem that
would give me access to the 'conversions.rb' file that has the 'to_date'
method.

I've tried doing this at the top of my script:

require 'activesupport/core_ext/date/conversions.rb'

Or whatever it is, but nothing is working.  Any thoughts?  I'd really
appreciate the help.  Thanks!
Ezra Z. (Guest)
on 2007-02-26 01:55
(Received via mailing list)
On Feb 25, 2007, at 3:35 PM, rph wrote:

> method.
>
> I've tried doing this at the top of my script:
>
> require 'activesupport/core_ext/date/conversions.rb'
>
> Or whatever it is, but nothing is working.  Any thoughts?  I'd really
> appreciate the help.  Thanks!
>

  At the top of your script do this:

require 'rubygems'
  require 'active_support'

Cheers-

-- Ezra Z.
-- Lead Rails Evangelist
-- removed_email_address@domain.invalid
-- Engine Y., Serious Rails Hosting
-- (866) 518-YARD (9273)
Rob B. (Guest)
on 2007-02-26 03:26
(Received via mailing list)
On Feb 25, 2007, at 6:53 PM, Ezra Z. wrote:

>> I'd like to use '.to_date' as that works fine from within the rails
>>
>
> -- Ezra Z.
> -- Lead Rails Evangelist
> -- removed_email_address@domain.invalid
> -- Engine Y., Serious Rails Hosting
> -- (866) 518-YARD (9273)

And if you need to specify a particular version:

require 'rubygems'
gem 'activesupport', '>=1.4'
require 'active_support'

Note that the name of the gem has no '_' (I beat my head on that one
a few weeks ago).  The 'gem' method sets up the load path for a
version of the gem that meets the requested restriction.

-Rob

Rob B.    http://agileconsultingllc.com
removed_email_address@domain.invalid
David A. Black (Guest)
on 2007-02-26 03:32
(Received via mailing list)
Hi --

On 2/25/07, rph <removed_email_address@domain.invalid> wrote:
> I've tried doing this at the top of my script:
>
> require 'activesupport/core_ext/date/conversions.rb'
>
> Or whatever it is, but nothing is working.  Any thoughts?  I'd really
> appreciate the help.  Thanks!

Try this:

  require 'rubygems'
  require 'active_support/core_ext/date/conversions'

(Note that you don't need, and actually should not use, the .rb
extension in a require, unless you're giving it a fully qualified path
to a file.)


David

--
Q. What is THE Ruby book for Rails developers?
A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black)
   (See what readers are saying!  http://www.rubypal.com/r4rrevs.pdf)
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (http://www.rubypal.com)
Ben W. (Guest)
on 2010-10-29 05:07
Please can anyone explain why this works in rails but not in irb ?

>> require 'active_support'
=> true
>> Time.now.beginning_of_day
NoMethodError: undefined method `beginning_of_day' for Fri Oct 29
14:05:28 +1300 2010:Time
  from (irb):2


Thanks
Ben

>   At the top of your script do this:
>
> require 'rubygems'
>   require 'active_support'
>
> Cheers-
>
> -- Ezra Z.
> -- Lead Rails Evangelist
> -- removed_email_address@domain.invalid
> -- Engine Y., Serious Rails Hosting
> -- (866) 518-YARD (9273)
Ben W. (Guest)
on 2010-11-01 00:19
Solved now,

>> require 'active_support/all'
=> true
>> Time.now.beginning_of_day
=> Mon Nov 01 00:00:00 1300 2010


Ben Williams wrote in post #957932:
> Please can anyone explain why this works in rails but not in irb ?
>
>>> require 'active_support'
> => true
>>> Time.now.beginning_of_day
> NoMethodError: undefined method `beginning_of_day' for Fri Oct 29
> 14:05:28 +1300 2010:Time
>   from (irb):2
>
>
> Thanks
> Ben
>
This topic is locked and can not be replied to.