如何显示附件中的图像?

How do I display an image from an attachment?

我想在以下代码块中显示我使用 CarrierWave 上传的图像。我可以定义图像大小吗?

  <%= simple_format(@employer.name) %>
   <% if @employer.attachment.present? %>
          <h4>Attachment</h4>
          <div class="attachment">
            <p>
              <%= link_to File.basename(@employer.attachment.url),
                @employer.attachment.url %>
             (<%= number_to_human_size(@employer.attachment.size) %>)
</p> </div>
<% end %>

使用image_tag:

<%= image_tag(@employer.attachment.url) %>

要定义自定义图像大小,请将版本添加到您的上传器。参见 documentation on adding versions

正如@Slava.K所说,使用image_tag。要更改图像大小,您可以使用 Imagemagick 和 MiniMagick,并在上传器中定义图像大小

请参阅 CarrierWave 文档:http://www.rubydoc.info/gems/carrierwave/