Im writing a module in the lib directory. If I change the module, the changes are not visible to the application when i releod the web page (i am in the development evironment). I must restart the web server (WEBrick) and so i see the changes... but I lost more time. How can I reload the module in the dirictory lib, without reload WEBrick? Thanks so much --Reis -- Posted via http://www.ruby-forum.com/.
In one of your files that do get reloaded (say the controller you''re working with) you can use a ''load'' statement, like load ''my_lib_file.rb'' A better answer, but maybe not immediately helpful: write unit tests to ensure the code in your lib file works. If you do test-based development, you don''t need to reload your lib constantly to see changes in the browser. cheers Gerret On 1/29/06, Reis <andrea.reginato@gmail.com> wrote:> Im writing a module in the lib directory. > If I change the module, the changes are not visible to the application > when i releod the web page (i am in the development evironment). > I must restart the web server (WEBrick) and so i see the changes... but > I lost more time. > > How can I reload the module in the dirictory lib, without reload > WEBrick? > > Thanks so much > --Reis > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Gerret Apelt wrote:> In one of your files that do get reloaded (say the controller you''re > working with) you can use a ''load'' statement, like > > load ''my_lib_file.rb''Thanks... it works, but it is not elegant as Ryby, because i must insert the load directive in all my controller. I''m serching the way for automatic loading the modules as rails do for the helpers. I need this for the the development evironment. Thanks so much for the answer. --Reis -- Posted via http://www.ruby-forum.com/.
Maybe in application controller: before_filter :load_my_lib def load_my_lib load ''my_lib.rb'' end 2006/1/29, Reis <andrea.reginato@gmail.com>:> Gerret Apelt wrote: > > In one of your files that do get reloaded (say the controller you''re > > working with) you can use a ''load'' statement, like > > > > load ''my_lib_file.rb'' > > Thanks... it works, but it is not elegant as Ryby, because i must insert > the load directive in all my controller. > I''m serching the way for automatic loading the modules as rails do for > the helpers. I need this for the the development evironment. > > Thanks so much for the answer. > --Reis > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 1/29/06, Reis <andrea.reginato@gmail.com> wrote:> Gerret Apelt wrote: > > In one of your files that do get reloaded (say the controller you''re > > working with) you can use a ''load'' statement, like > > > > load ''my_lib_file.rb'' > > Thanks... it works, but it is not elegant as Ryby, because i must insert > the load directive in all my controller. > I''m serching the way for automatic loading the modules as rails do for > the helpers. I need this for the the development evironment. >You can do "require_dependency" instead of "require", in your environment.rb file.
Wilson Bilkovich wrote:> On 1/29/06, Reis <andrea.reginato@gmail.com> wrote: >> > You can do "require_dependency" instead of "require", in your > environment.rb file.This is the solution I was searched... thanks so much to all. But the require_dependency must be setting in application_controller.rb, because in the environment.rb file the require and require_dependency do the same thing. Thanks --Reis -- Posted via http://www.ruby-forum.com/.
Reis wrote:> Wilson Bilkovich wrote: >> On 1/29/06, Reis <andrea.reginato@gmail.com> wrote: >>> >> You can do "require_dependency" instead of "require", in your >> environment.rb file. > > This is the solution I was searched... thanks so much to all. > But the require_dependency must be setting in application_controller.rb, > because in the environment.rb file the require and require_dependency do > the same thing. > > Thanks > --ReisA last question... Can I load all the module under a directory (only the first level) So if i have the dir lib with the module mod1.rb and mod2.rb, i can load them with a single command. Thanks --Reis -- Posted via http://www.ruby-forum.com/.
Hi Folks, I''m experiencing some puzzling behavior with a HABTM association. I have two models defined as follows: class Incident < ActiveRecord::Base has_and_belongs_to_many :conditions end Class Condition < ActiveRecord::Base has_and_belongs_to_many :incidents End When I run the following code (irb) the new Condition is not persisted to the DB until I call Incident#save. This is what I expect and is not the problem. i = Incident.new i.conditions << Condition.new(:name => ''some condition'') Now, my problem is when I add another condition to the saved incident. Like this... i.conditions << Condition.new(:name => ''some other condition'') At this point I would not expect to see the new condition persisted to the conditions DB table, but I do. Why is that? Shouldn''t the new condition be persisted to the DB only after I call i.save? On 1/29/06 11:22 AM, "Reis" <andrea.reginato@gmail.com> wrote:> Reis wrote: >> Wilson Bilkovich wrote: >>> On 1/29/06, Reis <andrea.reginato@gmail.com> wrote: >>>> >>> You can do "require_dependency" instead of "require", in your >>> environment.rb file. >> >> This is the solution I was searched... thanks so much to all. >> But the require_dependency must be setting in application_controller.rb, >> because in the environment.rb file the require and require_dependency do >> the same thing. >> >> Thanks >> --Reis > > A last question... > Can I load all the module under a directory (only the first level) > So if i have the dir lib with the module mod1.rb and mod2.rb, i can load > them with a single command. > > Thanks > --Reis
Sorry, first code block should read ... i = Incident.new i.conditions << Condition.new(:name => ''some condition'') i.save On 1/29/06 11:52 AM, "Vince Puzzella" <vpuz@rogers.com> wrote:> Hi Folks, > > I''m experiencing some puzzling behavior with a HABTM association. I have > two models defined as follows: > > class Incident < ActiveRecord::Base > has_and_belongs_to_many :conditions > end > > Class Condition < ActiveRecord::Base > has_and_belongs_to_many :incidents > End > > When I run the following code (irb) the new Condition is not persisted to > the DB until I call Incident#save. This is what I expect and is not the > problem. > > i = Incident.new > i.conditions << Condition.new(:name => ''some condition'') > > Now, my problem is when I add another condition to the saved incident. Like > this... > > i.conditions << Condition.new(:name => ''some other condition'') > > At this point I would not expect to see the new condition persisted to the > conditions DB table, but I do. > > Why is that? Shouldn''t the new condition be persisted to the DB only after > I call i.save? > > > > > > On 1/29/06 11:22 AM, "Reis" <andrea.reginato@gmail.com> wrote: > >> Reis wrote: >>> Wilson Bilkovich wrote: >>>> On 1/29/06, Reis <andrea.reginato@gmail.com> wrote: >>>>> >>>> You can do "require_dependency" instead of "require", in your >>>> environment.rb file. >>> >>> This is the solution I was searched... thanks so much to all. >>> But the require_dependency must be setting in application_controller.rb, >>> because in the environment.rb file the require and require_dependency do >>> the same thing. >>> >>> Thanks >>> --Reis >> >> A last question... >> Can I load all the module under a directory (only the first level) >> So if i have the dir lib with the module mod1.rb and mod2.rb, i can load >> them with a single command. >> >> Thanks >> --Reis > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
I''m not an expert, just a newbie What if you try class Incident < ActiveRecord::Base has_and_belongs_to_many :condition end Class Condition < ActiveRecord::Base has_and_belongs_to_many :incident End Instead of class Incident < ActiveRecord::Base has_and_belongs_to_many :conditions end Class Condition < ActiveRecord::Base has_and_belongs_to_many :incidents End -----Mensaje original----- De: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] En nombre de Vince Puzzella Enviado el: domingo, 29 de enero de 2006 13:53 Para: rails@lists.rubyonrails.org Asunto: [Rails] HABTM weirdness Hi Folks, I''m experiencing some puzzling behavior with a HABTM association. I have two models defined as follows: class Incident < ActiveRecord::Base has_and_belongs_to_many :conditions end Class Condition < ActiveRecord::Base has_and_belongs_to_many :incidents End When I run the following code (irb) the new Condition is not persisted to the DB until I call Incident#save. This is what I expect and is not the problem. i = Incident.new i.conditions << Condition.new(:name => ''some condition'') Now, my problem is when I add another condition to the saved incident. Like this... i.conditions << Condition.new(:name => ''some other condition'') At this point I would not expect to see the new condition persisted to the conditions DB table, but I do. Why is that? Shouldn''t the new condition be persisted to the DB only after I call i.save? On 1/29/06 11:22 AM, "Reis" <andrea.reginato@gmail.com> wrote:> Reis wrote: >> Wilson Bilkovich wrote: >>> On 1/29/06, Reis <andrea.reginato@gmail.com> wrote: >>>> >>> You can do "require_dependency" instead of "require", in your >>> environment.rb file. >> >> This is the solution I was searched... thanks so much to all. >> But the require_dependency must be setting inapplication_controller.rb,>> because in the environment.rb file the require and require_dependencydo>> the same thing. >> >> Thanks >> --Reis > > A last question... > Can I load all the module under a directory (only the first level) > So if i have the dir lib with the module mod1.rb and mod2.rb, i canload> them with a single command. > > Thanks > --Reis_______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails
That would change the collection name from Incident#conditions (plural and IMHO, more intuitive) to Incident#condition (singular). It does not address the problem. On 1/29/06 12:02 PM, "Rodrigo Dominguez" <ruby@rorra.com.ar> wrote:> > I''m not an expert, just a newbie > > What if you try > > class Incident < ActiveRecord::Base > has_and_belongs_to_many :condition > end > > Class Condition < ActiveRecord::Base > has_and_belongs_to_many :incident > End > > Instead of > > class Incident < ActiveRecord::Base > has_and_belongs_to_many :conditions > end > > Class Condition < ActiveRecord::Base > has_and_belongs_to_many :incidents > End > > > > > -----Mensaje original----- > De: rails-bounces@lists.rubyonrails.org > [mailto:rails-bounces@lists.rubyonrails.org] En nombre de Vince Puzzella > Enviado el: domingo, 29 de enero de 2006 13:53 > Para: rails@lists.rubyonrails.org > Asunto: [Rails] HABTM weirdness > > Hi Folks, > > I''m experiencing some puzzling behavior with a HABTM association. I > have > two models defined as follows: > > class Incident < ActiveRecord::Base > has_and_belongs_to_many :conditions > end > > Class Condition < ActiveRecord::Base > has_and_belongs_to_many :incidents > End > > When I run the following code (irb) the new Condition is not persisted > to > the DB until I call Incident#save. This is what I expect and is not the > problem. > > i = Incident.new > i.conditions << Condition.new(:name => ''some condition'') > > Now, my problem is when I add another condition to the saved incident. > Like > this... > > i.conditions << Condition.new(:name => ''some other condition'') > > At this point I would not expect to see the new condition persisted to > the > conditions DB table, but I do. > > Why is that? Shouldn''t the new condition be persisted to the DB only > after > I call i.save? > > > > > > On 1/29/06 11:22 AM, "Reis" <andrea.reginato@gmail.com> wrote: > >> Reis wrote: >>> Wilson Bilkovich wrote: >>>> On 1/29/06, Reis <andrea.reginato@gmail.com> wrote: >>>>> >>>> You can do "require_dependency" instead of "require", in your >>>> environment.rb file. >>> >>> This is the solution I was searched... thanks so much to all. >>> But the require_dependency must be setting in > application_controller.rb, >>> because in the environment.rb file the require and require_dependency > do >>> the same thing. >>> >>> Thanks >>> --Reis >> >> A last question... >> Can I load all the module under a directory (only the first level) >> So if i have the dir lib with the module mod1.rb and mod2.rb, i can > load >> them with a single command. >> >> Thanks >> --Reis > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Vince, You are experiencing the normal behaviour of the associations. From the RDOCs: # Adding an object to a collection (has_many or has_and_belongs_to_many) automatically saves that object, except if the parent object (the owner of the collection) is not yet stored in the database. # If saving any of the objects being added to a collection (via push or similar) fails, then push returns false. # You can add an object to a collection without automatically saving it by using the collection.build method (documented below). # All unsaved (new_record? == true) members of the collection are automatically saved when the parent is saved. You can read the rest of the documentation on associations at http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html Cody On 1/29/06, Vince Puzzella <vpuz@rogers.com> wrote:> Hi Folks, > > I''m experiencing some puzzling behavior with a HABTM association. I have > two models defined as follows: > > class Incident < ActiveRecord::Base > has_and_belongs_to_many :conditions > end > > Class Condition < ActiveRecord::Base > has_and_belongs_to_many :incidents > End > > When I run the following code (irb) the new Condition is not persisted to > the DB until I call Incident#save. This is what I expect and is not the > problem. > > i = Incident.new > i.conditions << Condition.new(:name => ''some condition'') > > Now, my problem is when I add another condition to the saved incident. Like > this... > > i.conditions << Condition.new(:name => ''some other condition'') > > At this point I would not expect to see the new condition persisted to the > conditions DB table, but I do. > > Why is that? Shouldn''t the new condition be persisted to the DB only after > I call i.save? > > > > > > On 1/29/06 11:22 AM, "Reis" <andrea.reginato@gmail.com> wrote: > > > Reis wrote: > >> Wilson Bilkovich wrote: > >>> On 1/29/06, Reis <andrea.reginato@gmail.com> wrote: > >>>> > >>> You can do "require_dependency" instead of "require", in your > >>> environment.rb file. > >> > >> This is the solution I was searched... thanks so much to all. > >> But the require_dependency must be setting in application_controller.rb, > >> because in the environment.rb file the require and require_dependency do > >> the same thing. > >> > >> Thanks > >> --Reis > > > > A last question... > > Can I load all the module under a directory (only the first level) > > So if i have the dir lib with the module mod1.rb and mod2.rb, i can load > > them with a single command. > > > > Thanks > > --Reis > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cody Fauser http://www.codyfauser.com
Reis, this should work Dir[File.join(RAILS_ROOT, ''lib'', "*.rb")].each do |file| require_dependency file end cheers Gerret On 1/29/06, Reis <andrea.reginato@gmail.com> wrote:> Reis wrote: > > Wilson Bilkovich wrote: > >> On 1/29/06, Reis <andrea.reginato@gmail.com> wrote: > >>> > >> You can do "require_dependency" instead of "require", in your > >> environment.rb file. > > > > This is the solution I was searched... thanks so much to all. > > But the require_dependency must be setting in application_controller.rb, > > because in the environment.rb file the require and require_dependency do > > the same thing. > > > > Thanks > > --Reis > > A last question... > Can I load all the module under a directory (only the first level) > So if i have the dir lib with the module mod1.rb and mod2.rb, i can load > them with a single command. > > Thanks > --Reis > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Gerret Apelt wrote:> Reis, this should work > > Dir[File.join(RAILS_ROOT, ''lib'', "*.rb")].each do |file| > require_dependency file > end > > cheers > GerretPerfect... this is the the solution i need. Thanks so much Garret! --Reis -- Posted via http://www.ruby-forum.com/.
Thanks Cody. That did the trick. Note to self: RTFM!!! On 1/29/06 1:00 PM, "Cody Fauser" <codyfauser@gmail.com> wrote:> Vince, > > You are experiencing the normal behaviour of the associations. From the > RDOCs: > > # Adding an object to a collection (has_many or > has_and_belongs_to_many) automatically saves that object, except if > the parent object (the owner of the collection) is not yet stored in > the database. > # If saving any of the objects being added to a collection (via push > or similar) fails, then push returns false. > # You can add an object to a collection without automatically saving > it by using the collection.build method (documented below). > # All unsaved (new_record? == true) members of the collection are > automatically saved when the parent is saved. > > You can read the rest of the documentation on associations at > http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html > > > > Cody > > > On 1/29/06, Vince Puzzella <vpuz@rogers.com> wrote: >> Hi Folks, >> >> I''m experiencing some puzzling behavior with a HABTM association. I have >> two models defined as follows: >> >> class Incident < ActiveRecord::Base >> has_and_belongs_to_many :conditions >> end >> >> Class Condition < ActiveRecord::Base >> has_and_belongs_to_many :incidents >> End >> >> When I run the following code (irb) the new Condition is not persisted to >> the DB until I call Incident#save. This is what I expect and is not the >> problem. >> >> i = Incident.new >> i.conditions << Condition.new(:name => ''some condition'') >> >> Now, my problem is when I add another condition to the saved incident. Like >> this... >> >> i.conditions << Condition.new(:name => ''some other condition'') >> >> At this point I would not expect to see the new condition persisted to the >> conditions DB table, but I do. >> >> Why is that? Shouldn''t the new condition be persisted to the DB only after >> I call i.save? >> >> >> >> >> >> On 1/29/06 11:22 AM, "Reis" <andrea.reginato@gmail.com> wrote: >> >>> Reis wrote: >>>> Wilson Bilkovich wrote: >>>>> On 1/29/06, Reis <andrea.reginato@gmail.com> wrote: >>>>>> >>>>> You can do "require_dependency" instead of "require", in your >>>>> environment.rb file. >>>> >>>> This is the solution I was searched... thanks so much to all. >>>> But the require_dependency must be setting in application_controller.rb, >>>> because in the environment.rb file the require and require_dependency do >>>> the same thing. >>>> >>>> Thanks >>>> --Reis >>> >>> A last question... >>> Can I load all the module under a directory (only the first level) >>> So if i have the dir lib with the module mod1.rb and mod2.rb, i can load >>> them with a single command. >>> >>> Thanks >>> --Reis >> >> >> _______________________________________________ >> Rails mailing list >> Rails@lists.rubyonrails.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > > -- > Cody Fauser > http://www.codyfauser.com > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
I''m having the same problem of not-reloading; not with modules, but just with any class that doesn''t inherit from a Rails class. I solved it by inserting ''include Reloadable'' in those classes. But I kind of dislike doing this: Rails should automatically reload everthing in the development environment, don''t you think so? :regards => Fino -- Posted via http://www.ruby-forum.com/.