Markus Jais
2005-Jun-22 18:13 UTC
Artilce about ActiveRecord: need your help with strange problem
Hi I am currently preparing an article about ActiveRecord for a german magazin including some advertising the ActiveRecord is really great. I am almost finished but I have one strange problem: I have a file called predator.rb. within this file there is this code: ========ActiveRecord::Base.establish_connection( .... ) class Predator < ActiveRecord::Base def to_s "id: #{id()} german_name: #{german_name()} english_name: #{english_name()}" end end ========= and I have a file called pred_prey.rb with this code: ======== ActiveRecord::Base.establish_connection( ... ) class Predator < ActiveRecord::Base has_and_belongs_to_many :prey, :join_table => "predators_prey" def to_s "id: #{id} german_name: #{german_name} english_name: #{english_name}" end end ..... ======== that is two Predator classes but in different files. I use each for a different database (different database name, but same table name (predators) In a third file create_pred_prey.rb I have this code: ========require "pred_prey" pred1 = Predator.new pred1.german_name = "Luchs" pred1.english_name = "Lynx" pred1.category = "Mammals" pred1.save ... ========but I get this message: ./predator.rb:18: warning: method redefined; discarding old to_s I made some checks and found out that both "predator.rb" and "pred_prey" are somehow required. so this yields this strange error. can anyone tell me why both files are required when I only call require "pred_prey" and never require "predator" regards Markus ___________________________________________________________ Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de
Michael Koziarski
2005-Jun-22 21:31 UTC
Re: Artilce about ActiveRecord: need your help with strange problem
On 6/23/05, Markus Jais <markus_jais-LWAfsSFWpa4@public.gmane.org> wrote:> Hi > > I am currently preparing an article about ActiveRecord > ./predator.rb:18: warning: method redefined; > discarding old to_s> can anyone tell me why both files are required when I > only call > require "pred_prey" > and never > require "predator"It''s probably activesupport''s automagic require functionality, it''s being helpful and ''loading'' predator.rb to pick up any changes you''ve made. Try renaming predator.rb to something else and see if it still happens. You could also use: Dependencies.mechanism = :require> regards > > Markus > > > > > > > > > > ___________________________________________________________ > Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Cheers Koz
Markus Jais
2005-Jun-23 09:13 UTC
Ant: Re: Artilce about ActiveRecord: need your help with strange problem
--- Michael Koziarski <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> schrieb:> On 6/23/05, Markus Jais <markus_jais-LWAfsSFWpa4@public.gmane.org> > wrote: > > Hi > > > > I am currently preparing an article about > ActiveRecord > > ./predator.rb:18: warning: method redefined; > > discarding old to_s > > > can anyone tell me why both files are required > when I > > only call > > require "pred_prey" > > and never > > require "predator" > > It''s probably activesupport''s automagic require > functionality, it''s > being helpful and ''loading'' predator.rb to pick up > any changes you''ve > made. Try renaming predator.rb to something else > and see if it still > happens. You could also use: > > Dependencies.mechanism > :require > > > > > regards > > > > Markus > >when I move predator.rb to another directory the problems are gone. maybe I will just use another classname and table name for my second example. that should avoid these problems. do you know where I can find documentation about activesupport''s automagic require functionality ?? regards markus ___________________________________________________________ Gesendet von Yahoo! Mail - Jetzt mit 1GB Speicher kostenlos - Hier anmelden: http://mail.yahoo.de