1 Jul
Ruby on Rails & Maths…
I have always been fascinated through Mathematics and how you can solve problems using it, we all know that in programming it is very useful. I recently had to use maths in a layout that I needed to form into a corporation for a new application…
Problem:
I had to display a dynamic list of border in a table, that was an x amount of rows and had 3 columns.
Solution:
I used Mod (the mathematical science of numbers that gives you the remainder of the division).
Therefore:
<table> <% r = 0 %> <% @count_suburb.each do |c| %> <% territory = Area.find_by_code(c[0])%> <% if ((r % 3) == 0) %> <tr> <% end %> <% r += 1%> <td>Write something here....<%= c.name.capitalize %></td> <% if ((r % 3) == 0) %> </tr> <% end %> <% close %> </table>
Does anyone apprehend of a better solution?
Thanks Annalisa
