1

所以我遇到了ruby这个问题,下面的代码解释了发生了什么

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”服务器,默认图像位于资产服务器上。

4

1 回答 1

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

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

于 2012-11-25T05:19:48.610 回答