Retrieving image from database to HTML

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:

3 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?

What are the field names for your classifieds table?

On Jun 23, 12:27 pm, Caiuby F. [email protected]

That is it…

create_table “categories”, :force => true do |t|
t.string “name”
end

create_table “classifieds”, :force => true do |t|
t.string “title”
t.float “price”
t.string “location”
t.text “description”
t.string “email”
t.datetime “created_at”
t.datetime “updated_at”
t.integer “category_id”
t.string “content_type”, :default => “image/png”
t.binary “image”
t.string “filename”
end

nickflux wrote:

What are the field names for your classifieds table?

On Jun 23, 12:27�pm, Caiuby F. [email protected]