Ruby on rails 4 回形针不能保存缩略图

Ruby on rails 4 回形针不能保存缩略图,ruby-on-rails-4,paperclip,Ruby On Rails 4,Paperclip,我在模型中有以下代码: has_attached_file :avatar, path: ':class/:attachment/:id/:style/:basename.:extension', :styles=> { :original => "500x500", :small => "200x200" }, default_url: "i

我在模型中有以下代码:

   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
In development.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

我缺少什么?

在您的模型中,您可以添加以下代码。不必担心代码中指定的大小,您可以将其更改为所需的大小

  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

在您的模型中,您可以添加以下代码。不必担心代码中指定的大小,您可以将其更改为所需的大小

  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