1

There is an answer to the question about how to make classes in lib folder be reloaded in development mode without having to restart server and worked partially.

So, I inserted following lines to development.rb file:

ActiveSupport::Dependencies.autoload_paths << File::join( Rails.root, 'lib')
ActiveSupport::Dependencies.explicitly_unloadable_constants.concat(['MyClass1', 'MyClass2'])

and yes, the class is reloaded on first source change, but on second change I get an exception:

Circular dependency detected while autoloading constant MyClass2

Why the exception is thrown about MyClass2 and not MyClass1? Because I instantiate it directly, and MyClass1 is used by MyClass2 later.

Here is some code:

The classes in lib\my_class1.rb:

require 'httpclient/include_client'

class MyClass2
  attr_reader :id, :login, :money, :info

  def initialize(parameters)
    @id = parameters['idUsers']
    @login = parameters['login']
    @money = parameters['money']
    @info = parameters['info']
  end
end

class MyClass1
  def initialize(parameters)
    @base_url = parameters[:base_url]
    @version = parameters[:version]
  end

  def get_test_data
    { huhu: "testvalue7"}
  end
end

Controller:

require 'my_class1'

class MyClassTestController < ApplicationController
  skip_before_filter :authenticate_user!

  def get_test_data_test
    ls = MyClass1.new({ base_url: 'http://192.168.0.25', version: '1'} )
    @res = ls.get_test_data
  end
end
Community
  • 1
  • 1
Paul
  • 25,812
  • 38
  • 124
  • 247

1 Answers1

1

Hey Paul thanks for update but I haven't found any mistake in your code.. Can you please check this link it may help you to solve your problem. http://teohm.com/blog/2013/01/10/reload-required-files-in-rails/

Gagan Gami
  • 10,121
  • 1
  • 29
  • 55
  • There is no code in Models. Or you consider that a class in lib folder is a model too? I've updated the question. P.S. You should understand that as soon as an accepted answer appears here this reply with all its comments should be deleted. And I wish that the accepted answer would be yours, so you'll get your reputation elevation honestly. – Paul May 14 '14 at 07:09