【问题标题】:Rails Prawn UnknownFormat (ActionController::UnknownFormat):Rails Prawn UnknownFormat (ActionController::UnknownFormat):
【发布时间】:2015-10-07 20:48:58
【问题描述】:

我是 Rails 新手,我正在尝试使用 Prawm 生成 pdf。我收到此错误: ActionController::UnknownFormat

代码如下:

def show_deposited_checks

deposit_id = params[:format]

if deposit_id.present?
  @payments = Payment.where(:deposit_id => deposit_id)
      respond_to do |format|
              format.html
              format.pdf do
                pdf = Prawn::Document.new
                pdf.text "Hello World"
                send_data pdf.render
                end 
      end        
else
  @payments = Payment.all.limit(10)
end 

结束

我从这里重定向:

redirect_to show_deposited_checks_payments_path(deposit)

我有另一种工作正常的方法,所以我怀疑它与重定向和控制器接收数据的方式有关。非常感谢任何帮助。

【问题讨论】:

    标签: ruby-on-rails prawn


    【解决方案1】:

    我认为问题在于 where 不会立即执行。可能有更好的方法(我对 Rails 也很陌生),但我认为这应该可行:

    @payments = Payment.where(:deposit_id => deposit_id).take(10) #或者你想加入多少

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-14
      • 2018-09-29
      • 1970-01-01
      • 2014-05-21
      • 2015-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多