【问题标题】:Paper Clip is not saving thumbnails回形针不保存缩略图
【发布时间】:2015-09-30 04:42:28
【问题描述】:

我在模型中有以下代码:

   has_attached_file :avatar, 
           path: ':class/:attachment/:id/:style/:basename.:extension', 
           :styles=> { :original => "500x500",
                      :small => "200x200"
                   }, default_url: "icons/user.png"

我还安装了 imagemagick。

which convert
/usr/bin/convert

开发中.rb

 Paperclip.options[:command_path] = %w(/usr/local/bin/ /usr/bin/)

我还尝试了以下方法:

   Paperclip.options[:command_path] = "/usr/bin/"

但是当我尝试上传图片时,它只保存原始文件。日志中的消息是:

[paperclip] saving user_profiles/avatars/53/original/2015-06-08-153213.jpg

我错过了什么?

【问题讨论】:

    标签: ruby-on-rails-4 paperclip


    【解决方案1】:

    在您的模型中,您可以添加以下代码。不用担心代码中指定的尺寸,你可以把它改成你需要的尺寸。

      has_attached_file :avatar, styles: { medium: '200x200>', thumb: '80x80>' }, default_url: "/icons/user.png"
      validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
    

    在您的情况下,转换路径是 /usr/bin/convert。这是默认路径。所以你不需要在你的 development.rb 文件中指定它。能否请您删除它并尝试一下。

    还要确保您的控制器中有允许的参数。

    示例代码

    # In Controller File
    private
    def user_params
      params.require(:user).permit(:email, :avatar)
    end
    

    【讨论】:

      猜你喜欢
      • 2011-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多