Wicked_PDF仅下载 - Rails 3.1

Amm*_*mar 4 pdf ruby-on-rails sendfile ruby-on-rails-3.1 wicked-pdf

我目前运行Rails 3.1并使用最新版本的Wicked_pdf进行PDF生成.我已经正确设置了所有内容,并且PDF生成得很好.

但是,我希望用户能够单击按钮以下载pdf.目前,单击时,浏览器将呈现pdf并将其显示在页面上.

<%= link_to "Download PDF", { :action => "show", :format => :pdf }, class: 'button nice red large radius', target: '_blank'%>
Run Code Online (Sandbox Code Playgroud)

我的控制器.

def show
    @curric = Curric.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @curric }
      format.pdf do
        render :pdf => @curric.name + " CV",
        :margin => {:top                => 20,  
                    :bottom             => 20 }

      end
    end
  end
Run Code Online (Sandbox Code Playgroud)

我被指向send_file,但绝对不知道如何在这种情况下使用它.

任何帮助表示赞赏.

aqu*_*ach 12

分解您需要设置为"附件"的配置,例如:

respond_to do |format|
  format.pdf do
    render pdf: @curric.name + " CV",
           disposition: 'attachment'
  end
end
Run Code Online (Sandbox Code Playgroud)

  • 你需要比这样更多的upvotes. (2认同)