views:

45

answers:

2

Hi Everyone,

I am using the Paperclip plugin to manage file uploads to my application. For some reason in the last day or so the plugin/model has stopped working and now returns the following error message:

Paperclip::PaperclipError in DeliversController#create

Asset model missing required attr_accessor for 'data_file_name'

As far as I am aware, I haven't touched the delivers controller or the paperclip plugin.

Has anyone seen this error before, or know how I can trace the last change on the file thats error'ing?

For reference the db schema is as follows:

 # Create Delivers Table
  create_table :delivers do |t|
    t.column :caseref, :string
    t.column :casesubject, :string
    t.column :description, :text
    t.column :document_file_name, :string
    t.column :document_content_type, :string
    t.column :document_file_size, :integer
    t.column :document_updated_at, :datetime
    t.timestamps
  end

   # Create Assets Table
   create_table :assets do |t|
     t.column :attachable_id, :integer
     t.column :attachable_type, :string
     t.column :date_file_name, :string
     t.column :date_content_type, :string
     t.column :date_file_size, :integer
     t.column :attachings_count, :integer, :default => 0
     t.column :created_at, :datetime
     t.column :date_updated_at, :datetime
     t.timestamps
  end

and the asset model is as follows:

class Asset < ActiveRecord::Base
  has_attached_file :data,
                    :url  => "/assets/:id",
                    :path => ":rails_root/assets/docs/:id/:style/:basename.:extension"

  belongs_to :attachable, :polymorphic => true

  def url(*args)
    data.url(*args)
  end

  def name
    data_file_name
  end

  def content_type
    data_content_type
  end

  def file_size
    data_file_size
  end
end

Thanks,

Danny

+1  A: 

Just try changing this

#Create Assets Table
create_table :assets do |t|
  t.column :attachable_id, :integer
  t.column :attachable_type, :string
  t.column :date_file_name, :string
  t.column :date_content_type, :string
  t.column :date_file_size, :integer
  t.column :attachings_count, :integer, :default => 0
  t.column :created_at, :datetime
  t.column :date_updated_at, :datetime
  t.timestamps
end

to this

# Create Assets Table
create_table :assets do |t|
  t.column :attachable_id, :integer
  t.column :attachable_type, :string
  t.column :data_file_name, :string
  t.column :data_content_type, :string
  t.column :data_file_size, :integer
  t.column :attachings_count, :integer, :default => 0
  t.column :created_at, :datetime
  t.column :date_updated_at, :datetime
  t.timestamps
end

I think the error message indicates it as

Asset model missing required attr_accessor for 'data_file_name'

Rohit
I have created a migration to rename the columns to data_X rather than date_X but I get the following error `No such column: assets.date_file_name` - it fixes the problem locally (on a new sqlite database) although not on the live server (mysql).
dannymcc
@dannymcc: It's a bad idea to develop on sqlite and than use mysql for production. Because there could be some problems with custom build queries, I would highly recommend to use mysql for development as well
jigfox
Hi Jigfox, I do need to get mysql working on my Mac for local development - I failed last time I tried. :(
dannymcc
+1  A: 
# Create Assets Table
t.column :date_file_name, :string
             ^^^

class Asset < ActiveRecord::Base
  has_attached_file :data,
                       ^^^

See the difference? Once it is datE and than it's datA

jigfox