Another newbie basic question. Here is a made up example:
I will have a 5 x 5 table display with numbers 11, 21, 31, 41, 51, in
the first row numbers 12, 22, 23, 24, 25 in the second row etc.
The table boxes will display the number of the parking slot and the name
of the car parked there from a hash I prepared from my car model in the
So each cell would have for example:
<td> ~ 11 ~ <br/> <%=h @parking_lot_hash if @parking_lot_hash%>
I could do that twenty five times and hardwire the rhtml form..
or I could achieve this in my view with:
<% 1.upto(5) do |row| %>
<% 1.upto(5) do |col|
space_num = row*10 + col %>
<td> ~ <%= space_num %> ~ <br/>
<%=h @parking_lot_hash[space_num] if
<% end %>
<% end %>
The first way would be 25 lines of text, compared to the 7 in the
But the second makes the computer think harder? And puts more logic in
It also makes a lot more sense at least to me. And honestly this is *presentation* logic, which is what should go into a view no? I don't think your violating any rules here and it makes things a lot simpler to look at.
If that table was going to be reloaded 7 times a minute by users
working on manipulating where cars were parked, would that tilt things
to the verbose first solution?
No. And as soon as the r/s gets high enough you'll want to cache it or do something else anyway.
Do servers calculate this stuff so effortlessly that I shouldn't even
begin to worry about it?
At 7 r/minute I wouldn't think about it all.