使用Prawn并尝试使用即时变量渲染图像的参数错误?

sju*_*own 3 pdf ruby-on-rails image prawn

我对编程比较陌生,这是我的第一个问题,所以我们走了:

尝试使用prawn渲染图像时出现以下错误:

ArgumentError in PropertiesController#show

/uploads/property/image/1/DSC_1749.JPG not found

Rails.root: /Users/Guest/Code/list
Run Code Online (Sandbox Code Playgroud)

我的代码

class PropertyPdf < Prawn::Document

def initialize(property)
  super(top_margin: 70)
  @property = property
  building_heading
  spacing
  building_info
  spacing2
  offer
  spacing2
  offer2
end

def building_heading
  text "#{@property.building_name}", size: 30, style: :bold
  text "#{@property.comment}", size: 23, style: :italic
  building_photo = "#{@property.image_url}"
  image building_photo, height: 200, width: 200
end

end
Run Code Online (Sandbox Code Playgroud)

显示控制器中的相关部分:

respond_to do |format|
     format.html # show.html.erb
     format.json { render json: @property }
     format.pdf do
           pdf = PropertyPdf.new(@property)
           send_data pdf.render, type: "application/pdf",
                                 disposition: "inline"
     end
end
Run Code Online (Sandbox Code Playgroud)

Ste*_*fan 5

您必须使用文件系统路径而不是URL.我假设您正在使用像CarrierWave或Paperclip这样的文件上传宝石.尝试

building_photo = @property.image_path
Run Code Online (Sandbox Code Playgroud)

要么

building_photo = @property.image.path
Run Code Online (Sandbox Code Playgroud)