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

  • SEARCH
  • Home
  • 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 7869383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:18:13+00:00 2026-06-03T01:18:13+00:00

My Ruby on Rails application needs to generate reports based on database records I

  • 0

My Ruby on Rails application needs to generate reports based on database records I have been storing the SQL and ERB code required to generate these reports in the database. Each reports is composed of three parts:

  • A header, which is an ERB snippet, rendered using <%= render inline: @report.header %>
  • A footer, which is another ERB snippet, rendered using <%= render inline: @report.footer %>

The body is then, of which the content are evaluated using @rows = eval("#{@report.model}.find_by_sql('#{@report.query}')"), rendered using:

<% @rows.each do |row| %>
  <tr>
    <% row.attributes.each_value do |value| %>
      <td><%= value %></td>
    <% end %>
  </tr>
<% end %>

The model in @report.model is the name of a Ruby class stored in a column.

While this gets the job done perfectly fine, I have started to feel uneasy about storing actual source code in the database. An alternative that has been proposed is instead of storing code in the database would be to store the code in files and from the database refer to those files. To me this does not sound much better (in fact it’s more of a hassle since instead of simply rendering the text in the database column, I have to go open and read the file as well).

What is the general consensus on storing source code like this in the database, and what are some (better) alternatives: Some considerations include:

  • New data is rarely added (we’re talking reports based on federal regulations that have not changed since 1999)
  • If it does need to be changed, it will never be modified by anyone other than me (while I obviously cannot predict the future, let’s for argument sake assume that this holds true).
  • The number of records is limited. We are talking about eight different reports here at most.
  • 1 1 Answer
  • 0 Views
  • 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. Editorial Team
    Editorial Team
    2026-06-03T01:18:14+00:00Added an answer on June 3, 2026 at 1:18 am

    I don’t have an issue storing code in the DB, but I do wonder, if it’s rarely added, and you’re the only person changing it, what you really gain by doing so (keeping it in the DB). I’m a little skeptical it’d be worth it unless it’s something that needs to change often. OTOH, IMO, no harm in doing so as long as it’s subject to the same testing the rest of your app gets.

    Templates in the DB–no problem with that either, although the same caveats apply. Note that particularly in Rails 3+, you can extend Rails to automatically retrieve templates from the DB, potentially saving yourself some manual work.

    I don’t know as there are any great other alternatives, although I’d probably consider uploaded files rather than DB blobs, if your concern is redeployment.

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

Sidebar

Related Questions

I have an Ruby on Rails 3 Heroku application, which needs to perform text
I currently have a Ruby (Rails) application that needs to make a lot of
I'm developing a Ruby on Rails application that needs to allow the user to
In my Ruby on Rails application, each group has_many :expenses. I have nested my
I have a ruby on rails application and it would be nice to see
I have to to deploy a Ruby on Rails application to an tomcat application
Okay I have an extensive ruby application running behind Ruby on Rails right now.
I have a CRUD application set up in Ruby on Rails 3 - its
I'm building a web application with Ruby on Rails which needs to be highly
I am running Ruby on Rails 3 and I have almost completed my application.

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.