How to use Active Support core extensions

前端 未结 5 2051
迷失自我
迷失自我 2020-11-28 04:49

I have Active Support 3.0.3 installed and Rails 3.0.3 with Ruby 1.8.7.

When I try to use 1.week.ago I get

NoMethodError: undefined meth         


        
5条回答
  •  囚心锁ツ
    2020-11-28 05:01

    You can granularly add libraries via the already mentioned

    require 'active_support/core_ext/some_class/some_file'
    

    There is also another level up where you can

    require 'active_support/core_ext/some_class'
    

    But, at the moment, this is unfortunately not available for Time, Date and DateTime.

    A way around this is to require 'active_support/time' which will give you Time, Date and DateTime which would solve the OP was asking for without requiring everything.


    My Rails patch, which adds active_support/core_ext/date and date_time, made it into Rails v4.0.0, so now you can require these individually. YAY!

提交回复
热议问题