Following is what I use for the same scenario (Better solutions
welcome)
I set one of these up for each database I use and use the appropriate
class method for each model to tell it where it resides.
The XXX_DATABASE is set in the environment.rb. Just contains the
database name.
I don’t use database_production either, the production database is
simply named database.
Also, my development database is also named database since it lives on
a different server. Those terms are just too long for my taste.
database_prod and database_dev would have been nicer.
#If the table you are creating the model for #lives in the xxx database, make the model #extend XxxDatabase instead of ActiveRecord::Base #Also, when setting the table name (“must”), use xxx_table_name
instead of set_table_name
module ARExtension
def self.included(base) #:nodoc:
base.extend(ClassMethods)
end
module ClassMethods
# use xxx_table_name "table_name" in your model
def xxx_table_name(value)
if RAILS_ENV == "production" || RAILS_ENV == "development"
set_table_name(XXX_DATABASE + "." + value)
else
#The test databases carry the _test at the end.
set_table_name(XXX_DATABASE + "_" + RAILS_ENV + "." + value )
end
end
end
end
class XxxDatabase < ActiveRecord::Base
include ARExtension
end
Let me know if does not make sense and I’ll explain further. When you
run tests, these will be used and the appropriate databases will be
used.
I am new to ruby on rails. we have developed application in rails it is
communicationg with PHP application.Everyhting is working fine.
I am using the two databases in the devlopment.(i.e one is PHP
application database and other one is Ruby on rails application)
If u r not clear about my application i will give more information…
Please give more points use two databases in the testing
I hope u will give more clear
-Karni
Fredrik wrote:
Following is what I use for the same scenario (Better solutions
welcome)
I set one of these up for each database I use and use the appropriate
class method for each model to tell it where it resides.
The XXX_DATABASE is set in the environment.rb. Just contains the
database name.
I don’t use database_production either, the production database is
simply named database.
Also, my development database is also named database since it lives on
a different server. Those terms are just too long for my taste.
database_prod and database_dev would have been nicer.
#If the table you are creating the model for #lives in the xxx database, make the model #extend XxxDatabase instead of ActiveRecord::Base #Also, when setting the table name (“must”), use xxx_table_name
instead of set_table_name
module ARExtension
def self.included(base) #:nodoc:
base.extend(ClassMethods)
end
module ClassMethods
# use xxx_table_name "table_name" in your model
def xxx_table_name(value)
if RAILS_ENV == "production" || RAILS_ENV == "development"
set_table_name(XXX_DATABASE + "." + value)
else
#The test databases carry the _test at the end.
set_table_name(XXX_DATABASE + "_" + RAILS_ENV + "." + value )
end
end
end
end
class XxxDatabase < ActiveRecord::Base
include ARExtension
end
Let me know if does not make sense and I’ll explain further. When you
run tests, these will be used and the appropriate databases will be
used.
Fredrik
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.