Prawn + Prawnto Issue

做~自己de王妃 提交于 2019-12-25 03:23:06

问题


I know prawn is working because I have a show action that if I add .pdf on to the end of it loads show.pdf.prawn. However, I have a form:

 <%= form_tag(:controller => "/holders", :action=> "generate", format: "pdf") do %>
      <%= label_tag(:count, "How Many Students?") %>
      <%= text_field_tag(:count) %>
      <%= hidden_field_tag :holder_id, value: @holder%>
      <%= submit_tag("Generate Course Lesson") %>
    <% end %>

That submits count to the the generate action.

Inside my generate action I have the following:

    def generate
        prawnto :filename => "print.pdf"
        respond_to do |format|
      format.html
      format.pdf { render :layout => false}
    end
  end

and my generate.pdf.prawn looks like:

pdf.text "HELLO WORLD"

When I submit the form I get the URL: http://localhost:3000/generate.pdf and Chrome tells me Failed to load PDF document with no other errors or information.

I noticed I am getting: Rendered holders/generate.pdf.erb in my dev logs which indicates its not even looking for the .prawn file.

What am I doing wrong?


回答1:


Setup your action like this:

def generate
  respond_to do |format|
    format.html
    format.pdf { prawnto :filename => 'print.pdf' }
  end
end


来源:https://stackoverflow.com/questions/11402723/prawn-prawnto-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!