Announcement (2017-05-07): www.ruby-forum.com is now read-only since I
unfortunately do not have the time to support and maintain the forum any
more. Please see rubyonrails.org/community and ruby-lang.org/en/community
for other Rails- und Ruby-related community platforms.

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

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

Gerret A. 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

Wilson B. wrote:
> On 1/29/06, Reis <removed_email_address@domain.invalid> 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

Reis wrote:
> Wilson B. wrote:>> On 1/29/06, Reis <removed_email_address@domain.invalid> 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

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?

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: removed_email_address@domain.invalid
[mailto:removed_email_address@domain.invalid] En nombre de Vince P.
Enviado el: domingo, 29 de enero de 2006 13:53
Para: removed_email_address@domain.invalid
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" <removed_email_address@domain.invalid> wrote:
> Reis wrote:>> Wilson B. wrote:>>> On 1/29/06, Reis <removed_email_address@domain.invalid> 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
removed_email_address@domain.invalid
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/As...
Cody
On 1/29/06, Vince P. <removed_email_address@domain.invalid> wrote:
> has_and_belongs_to_many :incidents> this...>> >>> > So if i have the dir lib with the module mod1.rb and mod2.rb, i can load>
--
Cody F.
http://www.codyfauser.com

Gerret A. wrote:
> Reis, this should work>> Dir[File.join(RAILS_ROOT, 'lib', "*.rb")].each do |file|> require_dependency file> end>> cheers> Gerret
Perfect... this is the the solution i need.
Thanks so much Garret!
--Reis

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