Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

AS dependency load order bug

#3544

When trying to use helpers like '3.hours.ago', requiring 'active_support/core_ext/numeric/time' on its own fails due to a dependency issue. The error I get is:

undefined method `current' for Time:Class
/home/rando/.rvm/gems/ruby/1.8.7/gems/activesupport-3.0.pre/lib/active_support/duration.rb:64:in `ago'

Further, 'duration' is also missing a dep on 'core_ext/object/acts_like'. Which additionally depends on core_ext/(date|time|date_time)/acts_like'. Also missing was 'core_ext/time/advance'.

So, to make '3.hours.ago' work, I had to require:

require 'active_support/core_ext/numeric/time'
require 'active_support/core_ext/object/acts_like'
require 'active_support/core_ext/time/acts_like'
require 'active_support/core_ext/time/calculations'

This does not include the equivalent ones to make date and datetime work as well.

Reported by Paul Sadauskas (Rando) · December 7th, 2009 @ 05:54 AM

State: resolved
Milestone: none
Assigned to: Ryan Bigg Ryan Bigg
Importance: Low

Activity

  1. David Trasbo
    David Trasbo
    • Assigned user set to Ryan Bigg

    This issue can be duplicated with Rails 2.3.5:

    ➜  code  rails -v
    Rails 2.3.5
    ➜  code  irb
    ruby-1.8.7-p249 > require 'rubygems'
     => true 
    ruby-1.8.7-p249 > require 'active_support/core_ext/numeric/time'
     => true 
    ruby-1.8.7-p249 > 42.days.ago
    NoMethodError: undefined method `current' for Time:Class
        from /Users/dtrasbo/.rvm/gems/ruby-1.8.7-p249/gems/activesupport-3.0.0.beta2/lib/active_support/duration.rb:67:in `ago'
        from (irb):4
    

    However, Rails 3 has been refactored to avoid this type of issues - all files (should) explicitly declare what they depend on so that they can be required stand-alone. I think this ticket can be closed, unless it would be relevant to fix this in the maintenance branch of Rails 2.3.

    April 14th, 2010 @ 09:08 PM

  2. Ryan Bigg
    Ryan Bigg
    • State changed from new to resolved

    Agreed.

    In Rails 3 there was a great ActiveSupport re-shuffling in order to be able to do things like this. I suggest moving to Rails 3 if you want it to be as simple as it should be.

    April 14th, 2010 @ 09:33 PM