ReporteController#opcionales 缺少此请求格式和变体的模板。 request.formats: ["application/pdf"] request.variant: []

ReporteController#opcionales is missing a template for this request format and variant. request.formats: ["application/pdf"] request.variant: []

"\nrequest.variant: #{request.variant.inspect}"

    raise ActionController::UnknownFormat, message
  elsif interactive_browser_request?
    message = "#{self.class.name}\##{action_name} is missing a template " \
      "for this request format and variant.\n\n" \

我的控制器

respond_to do |format|
  format.html
  format.pdf do
    pdf = Prawn::Document.new
    params[:id] = @ids
    @opcionales = Opcionale.where("id= ?", @ids)
    ...
    send_data pdf.render, filename: "Reporte_#{@opcionales}.pdf",
                        type: "application/pdf",
                        disposition: "inline"

  end
end

我的路线

得到'reporte/opcionales'

得到 'reporte/opcionales/:id',到:"reporte#opcionales",:defaults => { :format => 'pdf' }

在我看来

{<%= link_to "Generar PDF", '/reporte/opcionales/'+(opcionales.id.to_s)+'.pdf' %>}

转到 config/intializers/mime_types.rb 并添加 Mime::Type.register "application/pdf", :pdf,然后安装 gem 响应程序