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:

<img alt="3" src="/classified/imageload/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?
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to