Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 174807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:35:19+00:00 2026-05-11T13:35:19+00:00

I am developing an app that needs to send text messages, so I have

  • 0

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!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T13:35:19+00:00Added an answer on May 11, 2026 at 1:35 pm

    You can enable a Rake task to access your models by defining your task like this:

    task :my_task => :environment do   # Task code end 

    Note the => :environment, which grants this access. You can then instruct your Rake task to use different environments this way:

    rake RAILS_ENV=development my_task rake RAILS_ENV=production my_task 

    As for XML serialization, you can use the built-in to_xml method, such as:

    Carrier.all.to_xml 

    Note that the method .all is a recent addition to Rails, and is an alias for .find(:all).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 275k
  • Answers 275k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you're specifically looking for a replacement for LinearGradientBrush, there… May 13, 2026 at 2:36 pm
  • Editorial Team
    Editorial Team added an answer Creating them through the designer is exactly the same as… May 13, 2026 at 2:36 pm
  • Editorial Team
    Editorial Team added an answer Why don't you put these checks in the Load handler… May 13, 2026 at 2:36 pm

Related Questions

I am developing a client-server application - the server being an ASP .NET web
I am developing a Swing/Java app but having difficulties passing data from the initiliaser
I'm developing a project on google app engine (webapp framework). I need you people
I am developing an ASP.Net web app that needs to run in a Kiosk/Touch

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.