Rails 3 Wicked-pdf在窗口提交的新窗口中打开pdf

时间:2015-03-31 14:13:59

标签: ruby-on-rails wicked-pdf

我有一个包含表单的Rails 3索引视图,因为有选中行的复选框和使用Wicked-pdf创建所选记录的pdf的提交按钮。

我希望在新的浏览器标签中打开pdf。我在提交中添加了:target => "_blank",但它无效。

这是观点:

<%= form_tag costprojects_viewprojects_path(format: "pdf") do %>
...
<td><%= check_box_tag "costproject_ids[]", costproject.id %></td>
...
<%= submit_tag "PDF Selected", :target => "_blank", :class => 'btn btn-success' %>

控制器操作:

  def viewprojects
    @costprojects = Costproject.find(params[:costproject_ids])
    respond_to do |format|
      format.html
      format.pdf do
        render  :pdf => "costprojects.pdf",
                :show_as_html => params[:debug].present?,
                :page_size  => 'letter'
      end
    end
  end

感谢您的帮助!

1 个答案:

答案 0 :(得分:3)

试试这个

<%= submit_tag "PDF Selected", :formtarget => "_blank", :class => 'btn btn-success' %>