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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:38:29+00:00 2026-05-22T18:38:29+00:00

Up until now the MVC separation hasn’t given me any big problems, but I

  • 0

Up until now the MVC separation hasn’t given me any big problems, but I have to admit the “right” ruby/rails/dry/mvc way to tackle color-coded display of tabular data has eluded me.

My app has a page that shows 7 columns (days of week) with 20 rows of data (20 different products) that ranges from 0-100 in each cell. Each value is an average of between 50-500 rows in the database.

So the table is displaying 7×20=140 separate ‘average’ calculations representing up to 500 rows of data each.

Because of the amount of data being shown to the user, we need to color code the cells based upon the value: <25 = red, 25..75 = yellow, >75 = green

our method that does the calculation is product.get_daily_average(date)

We’re using HAML, btw.

The problem I have is figuring out where to put the code that specifies the color to apply to each cell…

…should there be if/then code to set the cell style (color) in the View? Is this a logical place for a Helper? Or should the model method that fetches the data “return” the html snippet with the color-code + data (instead of returning the value and letting the view handle the color)?

  • 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-22T18:38:30+00:00Added an answer on May 22, 2026 at 6:38 pm

    This is normally the type of thing that you would put in a helper method.

    In your view you’d do something like this (sorry, don’t know haml, this example is with erb)

    <%= daily_average_cell(product) %>
    

    And then in a helper

    def daily_average_cell(product)
      value = product.get_daily_average
      color = daily_average_color(value) # probably just make this method right here in the same helper module
      content_tag(:td, value, :class => color)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Up until now I have been using std::string in my C++ applications for embedded
I'm a ClearCase newbie and up until now have been used to SVN. Therefore,
From the .net 4.0 previews I have read until now there has been lots
I came across this recently, up until now I have been happily overriding the
I've never really had the need to use any drag functions until now, so
Which style of Ruby string quoting do you favour? Up until now I've always
Until now I've always used the ASP.NET MVC framework source for debugging ASP.NET MVC.
Until now deploying my Application with macdeployqt worked fine, but after upgrading to Qt
In ASP.NET we have until now only had one theme, which was specified in
I have built a standalone app version of a project that until now was

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.