> send_data @picture.data_file.data, :filename => @picture.filename,
> :type => @picture.content_type, :dispo sition => 'inline'
Shouldn't that be db_file, not data_file?
OOps. yes. But that just gets me to a different error message:
You have a nil object when you didn't expect it!
The error occured while evaluating nil.data
And while trying to double check that I had not messed anything up, I
am reminded that to get
as far as I did, I had had to comment out another piece of code that
was causing errors. So for a full recap:
I have Rails 1.1.6 installed on a RHEL 4 system running ruby 1.8.4
(installed from source). I installed acts_as_attachment using the
command "script/plugin install
If I set the DB environment variable, running the test "rake
test_plugins PLUGIN=acts_as_attachment" seems to work - but I had
expected more output - such as a list of # of tests and # passed.
If I set my Picture model up to use :storage => :file_system, all
seems to work just fine. To try to use :db_system, I needed to
uncomment the lines about db_file before running the migration built
when I did "script/generate attachment_model picture". Then I set up
my model up like:
class Picture < ActiveRecord::Base
acts_as_attachment :storage => :db_system, :max_size =>
500.kilobytes, :content_type => :image
and my controller like this:
class PictureController < ApplicationController
@pictures = Picture.find(:all)
@picture = Picture.new
@picture = Picture.find(params[:id])
send_data @picture.db_file.data, :filename => @picture.filename,
:type => @picture.content_type, :disposition => 'inline'
@picture = Picture.create params[:picture]
redirect_to :action => 'show', :id => @picture
render :action => 'new'
When I try to upload a new image, I can see the following exception:
undefined method `db_file_id=' for #<Picture:0xb77f83fc>
Application Trace | Framework Trace | Full Trace
In the module DbFileMethods section of acts_as_attachment.rb, I
commented out the line that calls db_file_id= and then I can upload
files. I see the insert statements for both db_files and pictures and
looking in the database, I see roughly the data I expect (Can't easily
inspect the image from the terminal, but it is of the same length as
the length stored in pictures.size. But when I try to use the show
method above, I get the nil.data error at the top of this post. And I
am having trouble working backwards from the only code that seems it
ties pictures to db_files to the syntax I need in my show controller
so I can display the images right out of the database. Is this the
code that tells the the two tables they are related?
module DbFileMethods def self.included(base) #:nodoc:
base.before_save :save_to_storage # so the db_file_id can be set
And I would have expected one or the other table to have a foreign
key. What am I missing?