I am developing an app that needs to send text messages, so I have carrier information stored in a database. I also need that information in an XML file for client side code to read. To make this happen, I am writing a script that reads the carrier information from the DB and creates an XML file in the config directory. I felt this script would fit best in lib/tasks.
I need to access the database from this script, but I want to use some object to access it. If I use
db = Mysql.new("domain", "username", "password", "database")
I will have to keep multiple versions for different environments because I do not use MySQL all the time. That would be very sloppy. I am sure there is a way to do this. I tried to just access the object...this is what I have so far:
RAILS_HOME = File.expand_path(File.join(File.dirname(__FILE__),"../.."))
RAILS_CONFIG = "#{RAILS_HOME}/config"
f = File.new("#{RAILS_CONFIG}/mls_widget_config.xml", "w")
carriers = Carrier.find_all
f.write carriers
f.close
But Carrier is not defined, which makes sense. How can I give this script access to the the Carrier object in the DB?
Also as a side, if anyone knows how to easily convert what I read from the DB into proper XML that would be great. I was going to write something custom real quick.
Thank you!