我想在下面的代码块中显示我使用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 %>
答案 0 :(得分:2)
使用image_tag
:
<%= image_tag(@employer.attachment.url) %>
要定义自定义图像大小,请将版本添加到上传器。见documentation on adding versions
答案 1 :(得分:1)
正如@ Slava.K所说使用image_tag
。要更改图像大小,您可以使用Imagemagick和MiniMagick,并在上传器中定义图像大小
请参阅CarrierWave的文档:http://www.rubydoc.info/gems/carrierwave/