我是 Ruby 和 RoR 的新手。我使用 Prawn 在 Ruby 中制作了一个 pdf 生成器。现在我想从我的 Rails 视图中执行它。
<%= form_for @assemble do |f| %>
<div class="row">
<div class="span2">
<h2 style="text-align: right;">Your</h2>
<ul id="download_ul">
<li style="margin-top: 5px;"><%= f.label :title_top %> </li>
<li style="margin-top: 13px;"><%= f.label :text_top %></li>
<li style="margin-top: 13px;"><%= f.label :link %></li>
<li style="margin-top: 13px;"><%= f.label :title_bottom %></li>
<li style="margin-top: 13px;"><%= f.label :text_bottom %></li>
<li style="margin-top: 13px;"><%= f.label :qr_code_url %></li>
<li style="margin-top: 13px;"><%= f.label :photo %></li>
<li style="margin-top: 13px;"><%= f.label :logo %></li>
<li style="margin-top: 10px;"><%= f.label :format %></li>
<li style="margin-top: 0px;"><%= f.label :cut_lines %></li>
</ul>
</div>
<div class="span3">
<h2>Information</h2>
<form method="post" action="../generate_pdf.rb">
<ul class="download_ul">
<li><%= f.text_field :title_top %></li>
<li><%= f.text_area :text_top%></li>
<li><%= f.text_field :link%></li>
<li><%= f.text_field :title_bottom %></li>
<li><%= f.text_area :text_bottom %></li>
<li><%= f.text_field :qr_code_url %></li>
<li><%= f.text_field :photo %></li>
<li><%= f.text_field :logo %></li>
<li style="margin-top: 6px;">
A4<%= f.check_box :format_a4 %>
A5<%= f.check_box :format_a5 %>
Letter<%= f.check_box :format_letter %>
Business card<%= f.check_box :format_business_card %>
</li>
<li style="margin-top: 6px;">
True<%= f.check_box :cut_lines_true, f.row %>
False<%= f.check_box :cut_lines_false %>
</li>
</ul>
<p><%= f.submit %>></p>
</form>
</div>
<div class="span6">
<h2>Example</h2>
<p><%= image_tag("a5.png", :size => "420x600") %></p>
</div>
</div>
<% end %>
要在 ruby 中执行我的 prawn-app,我使用 run.rb:
require '../lib/generator.rb'
PDFGenerator::A5.new(filename: "a5.pdf",
colors: {
instructions: "525149",
instructions_header: "000000",
panel: "001430",
experience: "FFFFFF",
qr_reader: "525149"
},
texts: {
qr_code_instructions: "*Some text ",
instructions_header: "Some text",
instructions: "Some text",
link: "Some text",
experience_header: "Some text",
experience: "Some text"
},
photo: "images/img.jpg",
qr_code: "images/qr.png",
logo: "images/logo.png").generate
我的控制器和模型文件:
class AssembleController < ApplicationController
def index
redirect_to new_assemble_path
end
def new
@assemble = Assemble.new
end
end
class Assemble < ActiveRecord::Base
# attr_accessible :title, :body
end
我希望很清楚我打算做什么。我很抱歉提出与其他人类似的问题,但我真的没有在我的代码中看到解决方案。