0
我使用Prawn
生成PDF。我创建了一个基本的index
视图,它可以进行一些简单的计算,并在按下提交按钮时显示答案。Ruby on Rails计算结果+对虾PDF生成器
问题是,我不知道如何采取这些答案,并将它们导出到虾。当我将它发送给Prawn时,它将输入到计算器的值重置为零,因此无论显示什么而不是计算出的答案,它都会显示相同的值。下面的MVC。真的很感谢任何帮助。
型号
class Calculator < ApplicationRecord
def self.to_celsius(fahrenheit)
(fahrenheit.to_i - 30)/2
end
def self.square_foot(a,b)
a.to_i * b.to_i
end
end
控制器
class CalculatorsController < ApplicationController
def new
@result = Calculator.to_celsius(params[:fahrenheit])
@square = Calculator.square_foot(params[:length], params[:width])
end
def index
@result = Calculator.to_celsius(params[:fahrenheit])
@square = Calculator.square_foot(params[:length], params[:width])
end
end
查看/ index.html.erb
<div class="row">
<div class="col-md-8 col-md-offset-2 calculations">
<%= form_for :calculators, url: { action: :new },method: :get do |f| %>
<p> Convert Celsius to Fahrenheit: </p>
<%= label_tag :fahrenheit, "Enter Fahrenheit", class: "input-a" %>
<%= text_field_tag :fahrenheit, params[:fahrenheit] %>
<p> Square Footage Calculator: </p>
<%= label_tag :length, "Enter length ft", class: "input-a" %>
<%= text_field_tag :length, params[:length] %>
<%= label_tag :width, "Enter width ft", class: "input-a" %>
<%= text_field_tag :width, params[:width] %>
<%= f.submit 'Calculate!' %>
<% end %>
<% unless @result.nil? %>
This is <p> = <%= @result %> degrees celsius! </p>
<% end %>
<p><%= link_to "Create PDF", calculators_path(:format => 'pdf') %></p>
</div>
</div>
和calculators_path'使用哪种方法'? – inye
@inye它连接到'index.pdf.prawn' – dgreen22