【问题标题】:Paperclip not saving image Rails 4回形针不保存图像Rails 4
【发布时间】:2016-07-12 10:36:11
【问题描述】:

我正在尝试使用 Paperclip 将图像保存到数据库,但附加图像并未保存到数据库。我正在使用 Windows。

模型类

has_attached_file :image, 
  :path => ":rails_root/public/system/:attachment/:id/:style/:filename",
  :url => "/system/:attachment/:id/:style/:filename",  
  :default_url => "/images/:style/missing.png"
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/

在控制器中:图像被添加到允许参数。

html.erb

<%= form_for @product, html: { multipart: true } do |f| %>
  <p>
    <%= f.label :image %><br />  
    <%= f.file_field :image %>
  </p>
  <p>
    <%= f.submit %>
  </p>
<% end %>

迁移已完成,字段在数据库中,但没有保存任何内容。 我正在使用 Paperclip 5.0.0 和 Rails 4.2.6

【问题讨论】:

标签: ruby-on-rails ruby-on-rails-4 paperclip


【解决方案1】:

通过不使用回形针和 CarrierWave 解决了我的问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-05
    • 2016-03-30
    • 1970-01-01
    相关资源
    最近更新 更多