Ruby on rails 用回形针上传图像?轨道4

Ruby on rails 用回形针上传图像?轨道4,ruby-on-rails,ruby-on-rails-4,paperclip,Ruby On Rails,Ruby On Rails 4,Paperclip,问题: 没有向数据库表中添加任何内容。请参阅下面的代码和错误。有人能解释一下我做错了什么吗?谢谢 用户型号: has_attached_file :avatar, styles: { thumb: "48x48>" }, default_url: "/assets/:style/missing.png" validates_attachment :avatar, content_type: { content_type: ["image/jpeg", "image/gif", "

问题: 没有向数据库表中添加任何内容。请参阅下面的代码和错误。有人能解释一下我做错了什么吗?谢谢


用户
型号:

  has_attached_file :avatar, styles: { thumb: "48x48>" }, default_url: "/assets/:style/missing.png"
  validates_attachment :avatar, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
仪表板
控制器:

  def update
    @user = User.find(current_user)
    @user.update( user_params )
    redirect_to dashboard_path
  end

  def user_params
    params.require(:user).permit(:avatar)
  end
路线:

  patch 'profile', to: 'user_dashboard#update'
表格/视图:

<%= form_for @user, url: profile_path, :html => { :multipart => true } do |f| %>
  <%= f.file_field :avatar %>
  <%= f.submit %>
<% end %>

发现此错误时存在github问题

解决方案应该是在application.rb中将以下内容设置为imagemagick安装路径

回形针。选项[:命令路径]=“/usr/local/bin/”

还可以尝试在{}中包装样式


在抓挠我的头一段时间后,附加了文件:阿凡达,{style:{thumb:{48x48>“}}

。。我通过执行以下操作找到了解决方案:

brew unlink libtool && brew link libtool
 #=>Unlinking /usr/local/Cellar/libtool/2.4.2... 0 symlinks removed
 #=>Linking /usr/local/Cellar/libtool/2.4.2... 17 symlinks created
并向Application.rb添加
回形针.options[:command_path]=“usr/local/bin/”

最后更新的用户#模型:


我相信
验证
也应该是
附加了文件
<代码>验证附件内容类型:头像,内容类型:/\Aimage\/.\Z/有什么区别?我正在显式定义内容类型。。。
/\Aimage\/.\Z/-
有什么作用?看起来你没有安装ImageMagick?没有。。我设法使它工作了。。请看下面我的回答:@Rich thanking!;)您是否使用自制软件安装imagemagick?如果是这样,imagemagick的安装路径可能是/usr/local/bin。此选项告诉回形针imagemagick在开发中的安装位置。打开application.rb文件或development.rb文件,将该行添加到该文件中,然后重新启动rails服务器。
  has_attached_file :avatar, default_url: "/assets/:style/missing.png"
  validates_attachment :avatar, content_type: { content_type: ["image/jpeg", "image/gif", "image/png"] }
brew unlink libtool && brew link libtool
 #=>Unlinking /usr/local/Cellar/libtool/2.4.2... 0 symlinks removed
 #=>Linking /usr/local/Cellar/libtool/2.4.2... 17 symlinks created
  has_attached_file :avatar, styles: {thumb: "100x100"}, default_url: "/assets/:style/missing.png"
  validates_attachment :avatar, :presence => true,
    :content_type => { :content_type => ["image/jpeg", "image/gif", "image/png"] },
    :size => { :in => 0..500.kilobytes }