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.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

problem with module loading

#5543

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

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

State: invalid
Milestone: none
Assigned to: nobody
Importance: Low

Activity

  1. Andrew White
    Andrew White
    • 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.

    September 3rd, 2010 @ 11:31 AM