I can upload an image to mysql database, but can´t render it on HTML
page.
I wrote the following acording to many snipets founded on the web.
Inside the controller (classified_controller.rb):
def imageload
@image = Classified.find(params[:id])
send_data (@image, :filename => @image.original_filename, :type =>
@image.content_type, :disposition => “inline”)
end
And in the view (show.html):
<% unless @classified.image.blank? %>
<%=image_tag(url_for({:controller => ‘classified’, :action =>
‘imageload’, :id => @classified.id}))%>
<% end %>
Here is my model (classified.rb):
class Classified < ActiveRecord::Base
belongs_to :category
validates_format_of :content_type, :with => /^image/, :message => “You
can only upload pictures”
def pictureimg=(picture_field)
return if picture_field.blank?
self.filename = picture_field.original_filename
self.content_type = picture_field.content_type.chomp
self.image = picture_field.read
end
end
After loading show.html, this is what I got:
and nothing is rendered.
I´m not understanding the path to the image. “imageload” is not a
directory but the name of a method defined in the controller.
Is there any other way to render the raw image from database directly to
the page (without creating any temporary file or something like it)?
Its worth to mention that the image was correctly saved. So my problem
is just retrieve it.
Does anyone know what am I missing?