【问题标题】:check if image exists on asset host and if not replace with a default image检查资产主机上是否存在图像,如果不存在则替换为默认图像
【发布时间】:2012-10-28 01:12:44
【问题描述】:

所以我遇到了 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”服务器,默认图像位于资产服务器上。

【问题讨论】:

    标签: ruby ruby-on-rails-3.2 asset-pipeline


    【解决方案1】:

    问题的解决方法如下

    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-07-23
      • 2016-01-20
      • 2015-06-03
      • 2022-01-08
      • 1970-01-01
      • 1970-01-01
      • 2014-03-27
      • 2021-02-11
      • 2012-01-31
      相关资源
      最近更新 更多