【问题标题】:rails 3 : paperclip : undefined method logorails 3:回形针:未定义的方法徽标
【发布时间】:2012-05-04 06:31:18
【问题描述】:

在模型中我有类似的东西

has_attached_file :logo, something_here

代码/上传徽标工作正常,但在上传徽标之前我需要尺寸。 所以当我使用几何时,会抛出错误

undefined local variable or method 'logo' for #<Class:0xbfabbc0>

知道如何解决这个问题吗?或者有没有其他方法可以在存储数据之前获取维度。

【问题讨论】:

    标签: ruby-on-rails paperclip undefined ruby-on-rails-3.2


    【解决方案1】:

    您可以连接到after_image_post_process。这是我的一个项目的工作代码:

    class Photo < ActiveRecord::Base
      has_attached_file :image
      after_image_post_process :save_thumb_file_size
    
      def save_thumb_file_size
        self.thumb_file_size = self.image.queued_for_write[:thumb].size if self.image.queued_for_write.key?(:thumb)
        return true
      end
    end
    

    【讨论】:

    • 我仍然遇到同样的错误。 '#<0xbdfee30>
    【解决方案2】:

    您是否生成了与该字段相关的迁移?

    rails generate paperclip photo logo
    

    然后运行 ​​rake db:migrate?

    【讨论】:

    • 是的,所有字段都在数据库中。成功上传徽标,但是当我尝试在保存之前获取尺寸时,它会引发错误。
    猜你喜欢
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 2018-08-26
    • 2013-12-17
    • 1970-01-01
    • 2011-08-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多