【问题标题】:Why am I getting a routing error on my ajax-loader.gif?为什么我的 ajax-loader.gif 出现路由错误?
【发布时间】:2014-07-20 02:49:56
【问题描述】:

我有一个运行良好的基于​​ JQueryMobile 的 Rails 应用程序,但我一直在日志中看到以下内容,我不知道如何摆脱它:

No route matches [GET] "/assets/images/ajax-loader.gif")

不过,我实际上在 /app/assets/images/ajax-loader.gif 中有我的 ajax-loader。另外,我很确定应用程序不应该尝试访问文件,因为我在应用程序中也有以下 JavaScript:

$(document).bind("mobileinit", function()
  $.mobile.ajaxEnabled = false;
});

我做错了什么?感谢您的帮助!

【问题讨论】:

    标签: ruby-on-rails jquery-mobile


    【解决方案1】:

    这没有错,对文件的请求是按照jqm css发出的

    .ui-icon-loading{background:url("images/ajax-loader.gif");background-size:2.875em 2.875em;}
    

    并且绝对路径将相对于您当前对 jqm css 路径的请求。因此是 404。

    对于Loading Widget,来自jqm官方文档

     It can also be displayed manually for custom loading actions using the $.mobile.loading helper method (See the global method docs).
    

    有两种解决方案。

    1. 相对于 jqm css 文件夹移动 images 文件夹。
    2. 在jqm css中更改背景图片url。

    我会推荐第一个。这将使您升级友好。

    【讨论】:

    • 事实证明,在这篇文章和一些实验之后,我能够通过创建资产/图像文件夹并将其移动到那里来摆脱错误。似乎没有其他任何工作。这让我走上了正确的轨道,但这并不是真正正确的,因为将它放在供应商/资产中实际上并没有帮助(我的 jqm css 在那里)。我仍然希望那里有更好的答案。
    【解决方案2】:

    通过在移动样式表的某处添加以下 CSS 规则来覆盖 jQuery 移动 CSS。

    我将它直接添加到我的移动清单文件 app/assets/stylesheets/mobile.css.scss 中,就在 //= require jquery.mobile-1.4.5.min.css 行的下方

    .ui-icon-loading { 背景:image-url('my-custom-ajax-loader.gif') !important; }

    通过使用 image-url 帮助程序,您可以获得资产管道的所有好处,例如指纹识别和 CDN 利用率。

    【讨论】:

    • 这对我也很有帮助,因为它添加到了我以前没有使用过的 !important 和 image-url 部分。现在,它们已被添加到我根据上述信息和此信息拼凑而成的解决方案中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 2013-11-26
    • 1970-01-01
    • 2013-05-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多