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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:19:04+00:00 2026-06-17T08:19:04+00:00

Ok so I am rendering a partial: <%= render :partial => box, :collection =>

  • 0

Ok so I am rendering a partial:

<%= render :partial => "box", :collection => @dashboard.charts %>

In the partial I am organising each “box” into rows of 3. Like this:

if box_counter % 3 == 0 && box_counter != 0
    %></div><div class='row'><%
end

which works great.

Here is my problem. I got my maths down but I’m not sure how to translate it into Ruby. Let me explain.

Each Box has a size. Small, Medium and Large. All sizes have been assigned a width. 20%, 30% and 50%. Which adds up to 100%.

A user can have any arrangement of these boxes in each row. What I need to do is check that the boxes in the row add up to 100%. So if its under or over 100% I will get the difference, divide it by 3 and add or remove that percent to each box therefor making each box add up to 100%.

For example. A user could have a combination of a Large Box, Large Box and then a Small Box. This adds up to 120%. So we get the difference, which is 20%, divide it by 3 = 6.6%, and then remove it from the 3 boxes (cause we went over 100%). So that becomes: LargeBox = 43.4%, LargeBox = 43.4%, Small Box = 13.4%. Which will add up to 100%. (or close to which is fine).

I’ve been working on this with Ruby and just don’t know how to get my maths into the loop or something. Really stuck here guys. I would appreciate the help.

Cheers.

  • 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-17T08:19:05+00:00Added an answer on June 17, 2026 at 8:19 am

    I don’t know Ruby, but since this is also tagged ‘math’, let me present a slightly different approach to the math that might be easier.

    If your sum is 120% (for instance), calculate a ratio of 100%/120% which gives you .833. Then multiply .833 by each of the three individual widths. There’s no need to perform three subtractions of different amounts this way. And 100%/100% = 1.0, so this same process still works correctly in either case.

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

Sidebar

Related Questions

I'm rendering a partial in a collection like this : <%= render :partial =>
I am rendering a partial like this: $(#box_container).html(<%= escape_javascript( render :partial => 'contacts/contact_tile', :collection
I rendering a view partially like this. <%= render(:partial => index ,:controller=>controller_name) %> so
I am rendering a partial like so: <% @pages.each do |page| %> <%= render
This is my code for rendering the partial (the @parties collection is being generated
I'm having trouble rendering out a template, my data looks like this: var data
In my views, I am rendering a partial. This is actually a row element
I have a collection that I rendering but would like to show a border
I am trying to render a partial on a collection with <%= render @posts
I currently am able to render a partial in JS like so: $(#cmtList_<%= @commentable.id

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.