我使用Paperclip已近一个月了,效果很好。在配置和测试准备工作中进行了一些修复之后它就会掉下来,现在它正在正确地保存图像,但是显示了类似于'%D0%97%D0%BD%D1%8F%D1%82%D0%BE%D0 %BA_%D0%B5%D0%BA%D1%80%D0%B0%D0%BD%D1%83_%D0%B7_2016-06-28_11-35-01'而不是图片本身。所有图片都是从文件字段标签上传的。你能告诉我如何解决这个问题或建议指南修补这类东西吗?
我的模特:
class Initiative < ActiveRecord::Base
paginates_per 3
include InitiativeStates
scope :searched, ->(query) { where('title LIKE ?', "%#{query}%") }
resourcify
belongs_to :user
has_many :timelines
has_many :initiative_categories
has_many :categories, through: :initiative_categories, class_name: 'Category'
accepts_nested_attributes_for :initiative_categories
accepts_nested_attributes_for :categories
has_attached_file :main_image,
path: ':rails_root/public/system/:attachment/:id/:style/:filename',
url: '/system/:attachment/:id/:style/:filename',
default_url: ':rails_root/public/default/def.phg'
validates :title,
presence: true
validates :short_description,
length: { maximum: 200 },
presence: true
validates :needed_sum,
inclusion: 100..50_000
validates_attachment :main_image,
content_type: { content_type: %w[image/jpeg image/gif image/png] },
presence: true
end
主要观点:
<div class="initiatives">
<div class="row">
<%@initiatives.each do |initiative| %>
<div class="col-md-4 col-sm-6 col-xs-12">
<%=render 'shared/short_view_initiative', initiative:initiative %>
</div>
<%= %>
<%end%>
</div>
倡议的分享:
<div class="initiative">
<%=link_to initiative_path(initiative) do%>
<div class="frame">
<%= image_tag initiative.main_image(:medium), class: 'initiative-image' %>
</div>
<%end%>
<div class="initiative-title">
<strong><%=initiative.title%></strong>
</div>
<div class="initiative-short-description">
<p><%=initiative.short_description %></p>
</div>
<% if user_signed_in? && (current_page? user_show_initiatives_path(current_user))%>
<div class="initiative-state">
<b><%=find_out_initiative_state(initiative)%></b>
</div>
<%end%>
</div>
控制器的一部分: class InitiativesController&lt; ApplicationController中
def index
@initiatives = Initiative.approved.order('approved_at ASC').page(params[:page])
end
end
我为它创建了一个适当的迁移,所有准备工作都已完成,一切正常。此外,img标签链接指向这些文件所在的正确目的地,但它不会渲染图像。