Reputation: 35
I am relatively new to programming and this is my first question so here we go:
I am getting the following error when trying to render an image with prawn:
ArgumentError in PropertiesController#show
/uploads/property/image/1/DSC_1749.JPG not found
Rails.root: /Users/Guest/Code/list
My code
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
Relevant Section in Show Controller:
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
Upvotes: 3
Views: 466
Reputation: 114188
You have to use the file system path instead of the url. I assume you're using a file upload gem like CarrierWave or Paperclip. Try
building_photo = @property.image_path
or
building_photo = @property.image.path
Upvotes: 5