1

我正在使用这个上传文件示例

我正在尝试修改附加文件的:url。它无法以某种方式工作。我在终端中收到此错误:

NoMethodError (undefined method `upload_file_size' for #<Paperclip::Attachment:0x8ca35e8>):

我的上传.rb:

class Upload < ActiveRecord::Base
  attr_accessible :upload, :upload_file_name, :upload_file_size

Paperclip::interpolates :upload_file_size do |attachment, style|
  attachment.instance.upload_file_size
end
  has_attached_file :upload,

                    :url =>"/system/Files/CEL-Files/:upload_file_size/:basename.:extension",
                    :path =>":rails_root/public/system/Files/CEL-Files/:piks/:basename.:extension"

  include Rails.application.routes.url_helpers

这是我的 schema.rb:

ActiveRecord::Schema.define(:version => 20120731045929) do

  create_table "uploads", :force => true do |t|
    t.string   "upload_file_name"
    t.string   "upload_content_type"
    t.string   "user"
    t.integer  "upload_file_size"
    t.datetime "upload_updated_at"
    t.datetime "created_at",          :null => false
    t.datetime "updated_at",          :null => false
  end

end

提前致谢

4

1 回答 1

1

您在回形针插值中使用的符号/字符串与您的模型属性“upload_file_size”冲突。尝试将回形针插值自定义名称从“upload_file_size”更改为其他名称。如下所示:

Paperclip::interpolates :size_of_file do |attachment, style|
  attachment.instance.upload_file_size
end
于 2012-11-18T14:41:46.800 回答