2017-10-21 67 views
0

我发现很难理解为什么回形针不调整我的图像。我遵循了文档,并通过将Paperclip.options[:command_path] = "/usr/local/bin/"放入其中来配置开发和生产文件。回形针不调整我的图像与引导

我已经在我的后期模型中检查了我的语法,看起来对我来说很好。我在我的索引视图中呈现了image_tag,并且我的照片正在显示,但尺寸不一样。我的意图是让回形针调整上传的每张图片的大小,以便我可以有美丽的图片向大家展示。

这里是我的模型:

class Post < ApplicationRecord 
    validates :image, presence: true 
    has_attached_file :image, styles: { :medium => "640x" } 
    validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/ 
end 

而我的观点:

<!DOCTYPE html> 
<html> 
    <head> 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous"> 
    <meta charset="utf-8"> 
    <title></title> 
    </head> 
    <body> 
    <div class="container-fluid"> 
    <div class="row"> 
     <% @post.each do |post| %> 
     <div class="col-sm-12 col-md-6 col-lg-3"> 
     <div class="panel panel-info"> 
     <%= post.caption %> 
     </div> 
     <a href="#" class="thumbnail"> 
     <%= image_tag post.image.url(:medium), class: "img-responsive"%> 
     </a> 
     </div> 
     <% end %> 
    </div> 

    </div> 
    </body> 
</html> 

我将根据要求提供的其他文件,如果我可以信任你。

+0

与回形针上传你的图片正确的(我的意思是,在最少保存,无论大小是否合适)?你想要获得什么样的图像? – Maxence

回答

0

我不太确定你的其他文件是什么样子,但我实际上在项目上使用Paperclip,这是我在项目索引页中所具有的。

<div class="card border-white" style="width: 15rem;"> 
<%= image_tag item.image.url, size: "250" %> 

它可能是你需要设置大小,而不是

class: img-responsive 

另外,我的项目波罗看起来像这样

class Item < ApplicationRecord 

has_attached_file :image, 
:default_url => '/images/missing.jpg', styles: {thumb: "68x68#", 
medium: "300x300#"}, 
:path => ":rails_root/public/images/:id/:style/:filename", 
:url => "/images/:id/:style/:filename" 
validates_attachment_content_type :image, content_type: ['image/jpeg', 
'image/jpg', 'image/gif', 'image/png']