ruby - Rails Time.now - 1.month not working -


i trying write simple script rails 2.3 application, encountering problem.

when start rails console , type time.now - 1.month gives correct output:

>> time.now - 1.month => mon dec 07 17:05:50 +0100 2015 

when use same piece of code inside file (script/foo.rb) error

undefined method 'month' 1:fixnum (nomethoderror) 

i not able require files "lib" directory. in rails 2.3 "lib" directory inside $load_path. problem has given me headache. can me.

here details system:

$ -a ruby /usr/bin/ruby /users/rakesh/.rvm/rubies/ruby-1.8.7-p374/bin/ruby 

the same script works fine on friend's machine guessing wrong in computer.

1.month comes active support, not ruby stdlib, need load dependency script context.

so, if want run custom script under whole rails environment (with dependencies loaded), should use rails runner:

runner runs ruby code in context of rails non-interactively

$ bin/rails runner path_to_your_script.rb 

in rails 2: script/runner.

alternatively, if need use active support methods, try explicitly require it: require 'active_support/core_ext/integer/time' , you'll able run script without loading rails (no need use runner).


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -