Hi From what I understand about documentation about require_dependency, this function will work like require but the file will be reloaded on every request to the server when in development mode. I have bootstrapped am minimal RoR project with 0.13.1 Rails. I have created a minimal Controller and hooked up it''s "index" action at the site root. I have also created a file config/my_config.rb which only has one line: CONFIG_SETTING = ''FOOBAR'' In my controller''s view, I assign CONFIG_SETTING''s value to a variable and display this variable in the index view of my controller. I include the config/my_config.rb file with: require_dependency ''my_config.rb'' at the end of config/environment.rb. My view displays ''FOOBAR'' fine. However, when I change the value in config/my_config.rb, the view still displays ''FOOBAR'' and not the value I changed the constant to. I also tried defining a class "Foo" there with a class method "bar" and the issue is the same: The change in the file is not reflected immediately as it should from my understanding since I am in "development" mode. What am I doing wrong? Regards Manuel Holtgrewe
On 9/27/05, Manuel Holtgrewe <purestorm-nlpEiS6K5uusTnJN9+BGXg@public.gmane.org> wrote:> Hi > > From what I understand about documentation about require_dependency, > this function will work like require but the file will be reloaded on > every request to the server when in development mode. > > I have bootstrapped am minimal RoR project with 0.13.1 Rails. I have > created a minimal Controller and hooked up it''s "index" action at the > site root. I have also created a file config/my_config.rb which only > has one line: > > CONFIG_SETTING = ''FOOBAR'' > > In my controller''s view, I assign CONFIG_SETTING''s value to a > variable and display this variable in the index view of my > controller. I include the config/my_config.rb file with: > > require_dependency ''my_config.rb'' > > at the end of config/environment.rb. > > My view displays ''FOOBAR'' fine. However, when I change the value in > config/my_config.rb, the view still displays ''FOOBAR'' and not the > value I changed the constant to. > > I also tried defining a class "Foo" there with a class method "bar" > and the issue is the same: The change in the file is not reflected > immediately as it should from my understanding since I am in > "development" mode. What am I doing wrong? > > Regards > > Manuel HoltgreweOff the top of my head, it might not be working since the require_dependency call is set in environment.rb? Also, I don''t believe you can reset constants. However, changing the class method should work. -- rick http://techno-weenie.net
Hi.> Off the top of my head, it might not be working since the > require_dependency call is set in environment.rb? Also, I don''t > believe you can reset constants. However, changing the class method > should work.How could I then implement configuration for my controllers that refreshes on every browser request? It works fine when I include the configuration file with require_dependency from the file defining the controller. I''d like to have a central place to include that configuration, though, and not in every controller. Regards Manuel Holtgrewe
On 9/27/05, Manuel Holtgrewe <purestorm-nlpEiS6K5uusTnJN9+BGXg@public.gmane.org> wrote:> Hi > > From what I understand about documentation about require_dependency, > this function will work like require but the file will be reloaded on > every request to the server when in development mode.That''s basically correct, but...> In my controller''s view, I assign CONFIG_SETTING''s value to a > variable and display this variable in the index view of my > controller. I include the config/my_config.rb file with: > > require_dependency ''my_config.rb'' > > at the end of config/environment.rb.environment.rb is only parsed once, when the server starts up, regardless of whether you are in development or production mode, IIRC. -- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland
I would think it would work if the require was in: app/controllers/application.rb That file is shared (mixed in?) to every controller. -- -- Tom Mornini On Sep 27, 2005, at 10:29 AM, Manuel Holtgrewe wrote:> Hi. > > >> Off the top of my head, it might not be working since the >> require_dependency call is set in environment.rb? Also, I don''t >> believe you can reset constants. However, changing the class method >> should work. >> > > How could I then implement configuration for my controllers that > refreshes on every browser request? It works fine when I include > the configuration file with require_dependency from the file > defining the controller. I''d like to have a central place to > include that configuration, though, and not in every controller. > > Regards > > Manuel Holtgrewe > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I found an interesting snippet in the trac database in response to a patch that was submitted for this: http://dev.rubyonrails.com/ticket/2098 I took took from it this little bit of code, which lives in environments/development.rb, and reloads anything inherited from the base class of my non-AR model(s): require ''dispatcher'' class Dispatcher class <<self alias_method :original_reset_application!, :reset_application! def reset_application! original_reset_application! Dependencies.remove_subclasses_for(SimpleModel) if defined?(SimpleModel) end end end No require_dependency needed, and I am encouraged to choose a single base class for my non-AR models (which I only need for transient purposes, hence the demeaning superclass name!) On 27 Sep 2005, at 19:50, Tom Mornini wrote:> I would think it would work if the require was in: > > app/controllers/application.rb > > That file is shared (mixed in?) to every controller. > > -- -- Tom Mornini > > > On Sep 27, 2005, at 10:29 AM, Manuel Holtgrewe wrote: > >> Hi. >> >> >>> Off the top of my head, it might not be working since the >>> require_dependency call is set in environment.rb? Also, I don''t >>> believe you can reset constants. However, changing the class method >>> should work. >>> >> >> How could I then implement configuration for my controllers that >> refreshes on every browser request? It works fine when I include the >> configuration file with require_dependency from the file defining the >> controller. I''d like to have a central place to include that >> configuration, though, and not in every controller. >> >> Regards >> >> Manuel Holtgrewe >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >