Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion no way to read image data from database

MIME-Version: 1.0
Received: by 10.100.77.10 with SMTP id z10mr544747ana.14.1257091542325; Sun, 
	01 Nov 2009 08:05:42 -0800 (PST)
Date: Sun, 1 Nov 2009 08:05:42 -0800 (PST)
X-IP: 222.212.112.72
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.4) 
	Gecko/20091016 Firefox/3.5.4,gzip(gfe),gzip(gfe)
Message-ID: <e102c78b-adf1-45b8-84e7-d99f1c116c85@a39g2000pre.googlegroups.com>
Subject: no way to read image data from database
From: daociyiyou <chey...@yahoo.com.cn>
To: "Ruby on Rails: Talk" <rubyonrails-talk@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1

db----
   def self.up
    create_table :db_files,:force => true do |t|
      t.binary :data
      t.timestamps
    end
  end
db----

controller----
def find_db_file
    project=Project.find_by_id(params[:id])
    project_snapshot=project.project_snapshot
    send_data(project_snapshot.db_file.data,
                              :type  => project_snapshot.content_type,
                              :filename => project_snapshot.filename,
                              :disposition => 'inline')
end
controller----


view-------
 <%for p in @projects -%>
  <%=image_tag(url_for
(:controller=>:projects,:action=>:find_db_file,:id=>p.id))-%>
 <%end-%>
view-------



I try my best to display the image data in the database,but fail.It
seems everything is right.Even try from mysql to sqlite not works.This