简体   繁体   English

Rails:'如果在本地运行'条件javascript标记包括

[英]Rails: 'if running locally' conditional javascript tag include

I want to load jQuery from http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js regularly, in production/development environment, as long as I'm not running locally, but my own local jquery.min.js if running locally (eg 0.0.0.0:3000 ) 我想定期在生产/开发环境中从http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js加载jQuery,只要我不在本地运行,如果在本地运行,我自己的本地jquery.min.js (例如0.0.0.0:3000

Reason why is that I have to do some development without internet connection sometimes, mostly when riding the subway. 原因是我有时候必须在没有互联网连接的情况下进行一些开发,主要是在乘坐地铁时。

I've been doing a if RAILS_ENV == 'development' conditional in the template, but it's annoying to have to change the template every time I need to force 'production' mode locally. 我一直在模板中做一个if RAILS_ENV == 'development'条件,但每次我需要在本地强制'生产'模式时必须更改模板很烦人。

I'm using haml btw.. not that it really matters. 我正在使用haml btw ..并不是真的很重要。

What's the best way to do this? 最好的方法是什么? Thanks 谢谢

ActionController has a method local_request? ActionController有一个方法local_request? . You will probably have to declare it as a helper_method to be able to use it in your views: 您可能必须将其声明为helper_method才能在视图中使用它:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM