【发布时间】:2011-03-25 19:42:09
【问题描述】:
好的,所以基本上我编写了这个应用程序,它对部分的每个点进行一些计算。这部分代码在控制器内处理,所以没关系。问题是我需要一些计算结果显示在屏幕上,以便我可以打印(到纸上)任何内容
<h2>Output for error calculations</h2>
<%
@sections.each_with_index do |section, sindex|
# Retrieve our values
total_distance = @total_distances[sindex]
@total_points_calc = @total_points_sections[sindex]
total_points = section.points.count
%>
<h3>Section <i><%= section.name %></i></h3>
<hr>
<p>\( \Sigma d_{<%= section.name %>} = <%= section.name %> \)</p>
<p>
\( \Sigma d_{<%= section.name %>}= \)
<%
section.points.each_with_index do |point, index| %>
<%=
# if this isn't the first section and the point.distance is 0
sindex != 0 and point.distance == 0 ? point.distance = nil : point.distance = point.distance
# add a + after each point that isn't the last
index != @total_points_calc ? point.distance.to_s + ' +' : point.distance
%>
<% end %>
= <%= total_distance%>
</p>
<p>
\( <%= section.name %>= \) <%= section.length %>
</p>
<p>e = \( \frac{<%= total_distance %> - <%= section.length %>}{<%= @total_points_calc %>} \) = <%= @errors[sindex] %></p>
<% end %>
这是一些示例输出http://img35.imageshack.us/i/screenshot20110325at133.png/ 完整的源代码可以在http://github.com/carvefx/Roadie找到。
我将如何以真正的 Rails 精神将这种逻辑的(部分)从视图中移开。看起来很奇怪的语法是 LaTeX,我需要它来在网络上输出数学。
【问题讨论】:
标签: ruby-on-rails view logic