【发布时间】: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