【问题标题】:Rails: 'if running locally' conditional javascript tag includeRails:'如果在本地运行'条件 JavaScript 标记包括
【发布时间】:2010-02-18 04:08:02
【问题描述】:

我想在生产/开发环境中定期从http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js 加载jQuery,只要我不是在本地运行,而是我自己的本地jquery.min.js 如果在本地运行(例如0.0.0.0:3000

原因是我有时必须在没有互联网连接的情况下进行一些开发,主要是在乘坐地铁时。

我一直在模板中使用if RAILS_ENV == 'development' 条件,但每次我需要在本地强制“生产”模式时都必须更改模板,这很烦人。

顺便说一句,我正在使用 haml .. 这并不重要。

最好的方法是什么?谢谢

【问题讨论】:

    标签: javascript jquery ruby-on-rails


    【解决方案1】:

    ActionController 有一个方法local_request?。您可能必须将其声明为 helper_method 才能在您的视图中使用它:

    class ApplicationController < ActionController::Base
        helper_method :local_request?
        ...
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      • 2018-05-25
      • 1970-01-01
      相关资源
      最近更新 更多