简体   繁体   中英

Rails Paperclip plugin stopped working?

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

# 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

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM