2010-08-26 47 views
1

我正在使用Paperclip插件来管理文件上传到我的应用程序。出于某种原因,在过去的一天左右的插件/模型已停止工作,现在返回以下错误信息:Rails回形针插件停止工作?

Paperclip::PaperclipError in DeliversController#create 

Asset model missing required attr_accessor for 'data_file_name' 

据我所知,我没有碰过的交付控制器或回形针插件。

有没有人见过这个错误之前,或知道我可以跟踪文件多数民众赞成错误的最后更改?

,以供参考DB模式如下:

# 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 

和资产模型如下:

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 

感谢,

丹尼

回答

2
# Create Assets Table 
t.column :date_file_name, :string 
      ^^^ 

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

看到区别了所需的attr_accessor?一旦它是datE和它的datA

1

刚刚尝试改变这种

#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 

这个

# 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 

我认为错误信息表明它作为

资产模型缺少 'data_file_name'

+0

我创建了一个迁移重命名列data_X而不是date_X,但我得到以下错误'没有这样的列:assets.date_file_name' - 它在本地修复了问题(在一个新的SQLite数据库),虽然不在现场服务器(MySQL)上。 – dannymcc 2010-08-26 20:37:53

+1

@dannymcc:在sqlite上开发并使用mysql进行生产是一个坏主意。因为定制构建查询可能会有一些问题,所以我强烈建议使用mysql进行开发。 – jigfox 2010-08-30 07:12:17

+0

嗨Jigfox,我需要让我的Mac在本地开发中使用mysql - 我上次尝试失败。 :( – dannymcc 2010-08-31 10:34:08