sprockets

如何在另一个JavaScript文件中包含一个JavaScript文件?

本小妞迷上赌 提交于 2019-12-06 01:54:01
JavaScript中是否有类似于CSS中 @import 的内容,可让您在另一个JavaScript文件中包含一个JavaScript文件? #1楼 而不是在运行时添加,而是使用脚本在上传之前进行串联。 我使用 链轮 (我不知道是否还有其他 链轮 )。 您将JavaScript代码构建在单独的文件中,并包含由Sprockets引擎处理的注释(包括)。 对于开发,您可以依次包含文件,然后在生产中将它们合并... 也可以看看: Sprockets简介:JavaScript依赖关系管理和串联 #2楼 如果有人在寻找更高级的东西,请尝试 RequireJS 。 您将获得更多好处,例如依赖管理,更好的并发性,并避免重复(也就是说,多次检索脚本)。 您可以在“模块”中编写JavaScript文件,然后在其他脚本中将它们作为依赖项引用。 或者,您可以将RequireJS用作简单的“获取此脚本”解决方案。 例: 将依赖项定义为模块: some-dependency.js define(['lib/dependency1', 'lib/dependency2'], function (d1, d2) { //Your actual script goes here. //The dependent scripts will be fetched if necessary. return

Requiring a sprockets-preprocessed file with Browserify and browserify-rails

大兔子大兔子 提交于 2019-12-06 00:34:00
问题 I'm using browserify-rails and I'm trying to get sprockets to preprocess a file that contains a sprockets directive, so that when I require() it using browserify, it will contain the generated JavaScript. The sprockets directive tries to include the output of the gem js-routes, in order to allow me to access the Rails routes from the clientside. This is my setup (within app/assets/javascripts ): system/ rails_routes.js application.js application.js is the main file, and it runs the rest of

Rails jquery-fileupload gem - couldn't find file error

ⅰ亾dé卋堺 提交于 2019-12-06 00:24:39
I'm trying to follow the Railscasts episode on jQuery-FileUpload. I've added gem 'jquery-fileupload-rails' to the assets group of the Gemfile , and also added the //= require jquery-fileupload/basic line to the application.js file in the asset directory. When I try to bring up the website, however, the following error is shown: couldn't find file 'jquery-fileupload' (in root/app/assets/javascripts/application.js:15) Any help would be greatly appreciated. I found a "solution" - restarting rails server did the trick. Remove it from assets group, and it'll work fine. I have fix this by : add gem

Rails - How to pass Sprockets::Context in manual sass compiling

筅森魡賤 提交于 2019-12-05 16:15:50
I'm using the following code snippet to manually compile a sass manifest with some variable overrides appended. template = File.read("#{Rails.root}/app/assets/schemes/#{scheme}/css/styles.css.scss") scheme_variables.each do |key, value| template << "$#{key}:#{value};\n" end engine = Sass::Engine.new(template, { :syntax => :scss, :cache => false, :read_cache => false, :style => :compressed, :filesystem_importer => Sass::Rails::SassImporter, :load_paths => MyApp::Application.assets.paths, :sprockets => { :context => ?, :environment => MyApp::Application.assets } }) output = engine.render The

sometimes javascript run perfect and sometimes not in ruby on rails 4

谁说我不能喝 提交于 2019-12-05 13:29:06
I used datepicker in calendar it shows perfect but not shows the arrow button to change month. and also give error sometimes like this: ActionController::RoutingError (No route matches [GET] "/assets/images/ui-icons_ef8c08_256x240.png") datepicker.js $(document).ready(function(){ $('[data-behaviour~=datepicker]').datepicker(); }); css link sorry for too long question and tell me if i miss something. Big thanks in advance Edit: I observed that when i delete the public/assets directory and then enter rake assets:precompile this time error is not showing but arrow still is not showing. It looks

Invalidate Sprockets cache during RSpec automated test

大城市里の小女人 提交于 2019-12-05 12:29:38
In my Rails application, I have a .js.erb file that has a variable which gets dynamically set based on some Ruby code. var myTimer = <%= MyApp.config.timeout_time * 1000 %>; The app works fine, but I'm having a problem in some automated tests. The problem occurs in an RSpec feature test that works with this JavaScript. My spec file has a number of tests that change the ruby MyApp.config.timeout_time time on the fly to test out different scenarios. In my spec file, the first example passes, and the rest fail. I finally realized this is happening because myTimer never gets updated on the

Rails dev environment not updating html/css/assets even after restarting server

拜拜、爱过 提交于 2019-12-05 12:25:03
问题 I've been developing a site in rails, everything going relatively smooth. Suddenly my changes to the views and assets no longer show up. I change a stylesheet or some html and reload my browser at http://0.0.0.0:3000 and nothing changes. So I restart WEBrick and still nothing's changed. This is even the case if I change an image entirely. The only way to get the new changes is to precompile the assets: C:\Users\me\website>rake assets:precompile C:/Ruby193/bin/ruby.exe C:/Ruby193/bin/rake

How to use Sprockets Rails plugin on Heroku?

夙愿已清 提交于 2019-12-05 07:30:44
问题 I just deployed my Rails app to Heroku, but the Javascripts that were using Sprockets plugin don't work. I understood that, because my Heroku app is read-only, Sprockets won't work. I've found this sprockets_on_heroku plugin that should do the work, but I don't really get how to use it : I added config.gem sprockets in config/environment.rb I added sprockets in my .gems file I pushed these on Heroku and Sprockets was successfully installed I locally ran script/plugin install git://github.com

How to use Sprockets 2 with Rails 3.0.x (how to use precompiled assets)

天涯浪子 提交于 2019-12-05 02:03:51
问题 I'm trying to replicate the basics of the asset pipeline introduced in rails 3.1 in my rails 3.0 app . So far, I've got something like this: https://gist.github.com/1112393. It works great: I have my assets in app/assets/, lib/assets, vendor/assets... They're all served at /assets I can use everything sprockets 2 offers etc... The thing is, I don't want the rails app to serve static assets. The server should do it. That's why you can precompile assets in rails 3.1, if I understood correctly.

Rails asset pipeline and digest values

送分小仙女□ 提交于 2019-12-04 23:28:30
问题 Does anyone know how exactly the asset digest value is calculated? If I have two JS files which contain various other included JS scripts then will each file maintain the same digest hash if none of the inner scripts have been changed? Or is a new digest value calculated each time the assets:precompile operation is run? 回答1: Grabbed from rails guides When a filename is unique and based on its content, HTTP headers can be set to encourage caches everywhere (whether at CDNs, at ISPs, in