This project is archived and is in readonly mode.

#5543 ✓invalid
Alexey Poimtsev

problem with module loading

Reported by Alexey Poimtsev | September 3rd, 2010 @ 10:08 AM

Hi,
I have some module called lib/test_mod.rb with code

module TestMod
  def self.included m
    return unless m < ActionController::Base
    m.helper_method :tst_helper
  end
  def tst_helper
    raise "test"
  end
end

and controller

class Nsp::UsersController < ApplicationController
  include TestMod
  
  def index
    tst_helper
  end

end

Everything looks good, but on attempt to request "index" method i see error

Routing Error


uninitialized constant Nsp::UsersController::TestMod

Source in attachment

Comments and changes to this ticket

  • Andrew White

    Andrew White September 3rd, 2010 @ 11:31 AM

    • State changed from “new” to “invalid”
    • Importance changed from “” to “Low”

    In Rails 3 files in lib are no longer autoloaded - you need to require them explicitly, e.g:

    require 'test_mod'
    
    class Nsp::UsersController < ApplicationController
      include TestMod
      
      def index
        tst_helper
      end
    
    end
    

    The reason for this is that autoload paths are eagerly loaded in production and the lib path may contain files you don't want in a production app like tasks, generators, etc.

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>

Attachments

Pages