3

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

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

ArgumentError in PropertiesController#show

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

Rails.root: /Users/Guest/Code/list

我的代码

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

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

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
4

1 回答 1

5

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

building_photo = @property.image_path

或者

building_photo = @property.image.path
于 2013-06-13T23:17:05.133 回答