This project is archived and is in readonly mode.

#3544 ✓resolved
Paul Sadauskas (Rando)

AS dependency load order bug

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

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.

Comments and changes to this ticket

  • David Trasbo

    David Trasbo April 14th, 2010 @ 09:08 PM

    • 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.

  • Ryan Bigg

    Ryan Bigg April 14th, 2010 @ 09:33 PM

    • 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.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages