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 6979675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:54:59+00:00 2026-05-27T17:54:59+00:00

Rails 2.3.5 I have a report being created on 3 different views (main, pre-view,

  • 0

Rails 2.3.5

I have a report being created on 3 different views (main, pre-view, and a layout-free plain HTML version for an auto email). The report uses about 28 queries and for some of those queries I’m doing some logic before the query:

  sunday_this_week = (Time.now.beginning_of_week - 1.days).strftime("%Y-%m-%d")
  sunday_1_week_ago = (Time.now.beginning_of_week - 8.days).strftime("%Y-%m-%d")
  sunday_2_week_ago = (Time.now.beginning_of_week - 15.days).strftime("%Y-%m-%d")
  sunday_3_week_ago = (Time.now.beginning_of_week - 22.days).strftime("%Y-%m-%d")
  sunday_4_week_ago = (Time.now.beginning_of_week - 29.days).strftime("%Y-%m-%d")
  @sunday_dates = [sunday_this_week,sunday_1_week_ago,sunday_2_week_ago,sunday_3_week_ago,sunday_4_week_ago ]

  sql = %Q{
           SELECT * FROM report_notes
           WHERE week_of IN(?)
           ORDER BY week_of ASC, market ASC, measure ASC
          }
  @performance_metric_notes = RptNote.find_by_sql([ sql, @sunday_dates ])

Some of the queries are really large and since 3 views need them, I have the same queries listed under three differenct controller mthods. There’s a lot of lines in the controller (~1400 lines).

What would you do to refactor something like ( is it possible to have a single controller method with all the query setup logic and queries, that the 3 different view methods can call instead of each view method having a copy )?

Thanks!

  • 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-05-27T17:55:00+00:00Added an answer on May 27, 2026 at 5:55 pm

    I would extract all of this code in a separate Report class.
    Moving it to another controller action would still result in a huge controller. Plus, if there is a lot of logic to generate the report, the controller action is not the right place for it. It’s a lot better if you can keep your controllers clean, just preparing variables for the views.

    Just put your class in /lib, and in your controller actions you can call something like

    report = Report.new params
    @performance_metric_notes = report.performance_metric_notes
    @other_performances = report.other_performances
    ...
    

    You get the idea.

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

Sidebar

Related Questions

I have a Rails view that produces a HTML report based on the user
I have a rails app with working reports that have tags. In the Report/Index.html.erb
Netbeans 6.9 JRuby 1.5.0 rails 2.3.4 Error example: NoMethodError in Report#week Showing app/views/report/_list_record.html.erb where
I'm using jQuery with rails and have the following piece of code $('#related').html(<%= render
It's getting old rewriting report code for Rails applications. Ya have to create the
I have a rails app that tracks membership cardholders, and needs to report on
I have a Rails application that generates a weekly report and emails it out.
I have this ffmpeg video encoder using Rails and I needed to report ffmpeg
I have Rails 3.1.3 app and trying to plug gem redis to it. I've
I have rails app which are working perfectly in the local computer. But when

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.