2015-06-05 38 views
0

我正在使用Cloudinary gem和Attachinary一起做类似pinterest的应用程序。如果创建的Pin没有一个或图像加载不正确,我在我的index.html.erb文件中添加了一行,该文件应该显示默认图像。为让他们正确显示引脚的图像,但对于那些谁不只是一个粗线条可见(jQuery的砌体网格) -Rails:Cloudinary gem - 默认图像不加载

<% if pin.image.present? %> 
        <%= link_to pin do %> 
        <%= cl_image_tag(pin.image.path) %> 

      <% end %>  

      <% if pin.image.present? == false %> 
        <%= cl_image_tag('no-image-found_jqqruy') %> 

       <% end %>  

遗憾的是它不工作。我想知道用cloudinary设置默认图像的正确方法是什么。我哪里做错了?这里是我的全部索引文件:

<div id="pins" class="transitions-enabled"> 

     <% @pins.each do |pin| %> 
      <div class="container"> 
      <div class="box panel panel-default"> 

      <% if pin.image.present? %> 
        <%= link_to pin do %> 
        <%= cl_image_tag(pin.image.path) %> 

      <% end %>  

      <% if pin.image.present? == false %> 
        <%= cl_image_tag('no-image-found_jqqruy') %> 


      <% end %>  


      <div class="panel-body"> 

      <%= pin.description %> <br> 
      <strong><%= pin.user.email if pin.user %></strong> 

      <% if pin.user == current_user && user_signed_in? %> 
       <div class="actions"> 
        <%= link_to edit_pin_path(pin) do %> 
        <span class="glyphicon glyphicon-edit black"></span> 
         Edit 
         <% end %> 

        <%= link_to pin, method: :delete, data: { confirm: 'Are you sure?' } do %> 
        <span class="glyphicon glyphicon-trash black"></span> 
         Delete 


          </div>  

         <% end %>  
         <% end %> 
         </div>  
        <% end %> 
       </div> 
      <% end %>    
      </div> 

我只补充一点,直到我已经介绍了glyphicons一切正常。

我将非常感谢您的帮助!

回答

0

如果没有复制粘贴&错误,有一个额外的end缺少终止link_to pin do声明。因此,第一个if声明仍处于活动状态,然后会查询相反的if声明,这当然不会是真实的。

我建议使用if-else-end。

<% if pin.image.present? %> 
    <%= link_to pin do %> 
    <%= cl_image_tag(pin.image.path) %> 
    <% end %>  
<% else %> 
    <%= cl_image_tag('no-image-found_jqqruy') %> 
<% end %>