在wicked_pdf中不生成PDF

时间:2017-04-25 05:47:29

标签: jquery ruby-on-rails ajax pdf wicked-pdf

我是rails的新手,我想将html页面转换为pdf。我正在使用wicked_pdf gem。我的问题是应该为两种类型的用户(经理,员工)生成pdf。对于普通员工来说,pdf是正确生成的。但是当经理试图生成pdf时他就不能给我代码。

这是我的控制器

  @time_entries = TimeEntry.find(params[:ids])
    @project = Project.find_by_id(params[:project_id])
    @upcoming_week_tasks = @project.issues.open
    opened_risks = Risk.where(project_identifier:     @project.identifier, status: Risk.get_open_statuses )
    closed_risks = Risk.where("project_identifier = ? and updated_at >= ? and updated_at <= ? and status in (?)", @project.identifier,    params[:wsr_start_date],params[:wsr_end_date], Risk.get_closed_statuses)
    @risks = opened_risks + closed_risks
    respond_to do |format|
      format.js do
        render :partial => "wsr_entries", :content_type => 'text/html'
      end
      format.pdf do
        render pdf: "PRR-#{@project.name}", template: "wsr/prr.html.erb"
      end
    end
  end

我使用ajax函数来获取控制器的参数。函数如下所示

    $("#pdf_link").click(function(e){
  e.preventDefault();
  var ids = [];
  var project_id = $("#project_id").find(":selected").attr('value');
    $(".list input[type=checkbox]:checked").each(function(){
      ids.push($(this).attr('value'));
    });

  $.ajax({
    url: '/get_prr.pdf',
    type: 'POST',
    data: {ids: ids, project_id: project_id }
  });
});

,视图中的链接标记为

<% action_path = @managers.include?(@user) ? get_prr_path(:format => "pdf") : weekly_status_report_path(:format => "pdf")%>
  <p id="pdf_link" style="display:none;"><%= link_to "Download PDF", action_path %></p>

当普通用户点击链接时,它应该转到weekly_status_report_path,当经理点击它时,应该转到get_prr_path。

问题是两个动作都做得很好但是没有生成pdf

当我检查控制台时,它会给出以下引用

  Rendered wsr/_summary_of_time_entries.html.erb (6.2ms)
  Rendered wsr/prr.html.erb (8.6ms)
"***************[\"/home/likewise-open/CHENNAI/001133/.rvm/gems/ruby-    2.2.2@redmine1/bin/wkhtmltopdf\", \"-q\",  \"file:////tmp/wicked_pdf20170425-20985-1kfny53.html\", \"/tmp/wicked_pdf_generated_file20170425-20985-1ke6sll.pdf\"]***************"
  Rendered text template (0.0ms)
Sent data PRR-WSR task check.pdf (2.2ms)
Completed 200 OK in 1061ms 

我想问题是ajax功能。

提前感谢,抱歉我的英语不好:)

1 个答案:

答案 0 :(得分:0)

尝试将Function PreIncr(ByRef x As Integer) As Integer ' PreIncr(i) works like ++i x += 1 : Return x End Function 添加到format.html块中。我认为respond_to希望它存在,即使你不能使用它。

wicked_pdf