2012-10-28 79 views
1

所以我有红宝石这个问题,下面的代码解释了什么是对检查,如果不使用默认的图像替换

def image_full(img,options) 
    if Jjdowns::Application.assets.find_asset("#{img}").nil? 
      image_full = image_tag("#{img}",options) 
    else 
      image_full = image_tag("app/no-image-large.png", options) 
    end 
  end 

什么,我试图做的是运行会检查我的资产服务器上是否存在图像,如果存在,则显示原始图像。如果在资产服务器上找不到图像,那么我想显示一个默认图像。

此代码块用于显示图像,但显示默认图像的部分不起作用。

到目前为止,我的研究结果并没有解决这个问题。

只是为了阐明资产服务器是内部“CDN”服务器,默认映像位于资产服务器上。

回答

0

的解决问题的方法结束了以下

def some_image(img,options) 
    default_img = "dir_to_image/no-image-filler.png" 
    if ("#{img}") != '' 
      default_img = "#{img}" 
    end 
    some_image = image_tag(default_img, options)    
end 

这里的关键的是,我们有一个单独的服务器上运行的外部资产主机,这是最初的问题。

相关问题