sprockets

Rails Assets Best Practices [closed]

♀尐吖头ヾ 提交于 2019-12-09 08:13:58
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . I'm new to Rails, and having trouble figuring out the best way to organize my assets. The purpose of this question is to collect my thoughts, solicit input, and evolve the document over time - perhaps it can be a

rake assets:precompile:nodigest in Rails 4

倾然丶 夕夏残阳落幕 提交于 2019-12-09 02:41:55
问题 In Rails 3 there was a rake assets:precompile:nodigest task which was compiling assets and writing them without the digest part in /public/assets directory. In Rails 4 this has been removed, and by default all assets are precompiled with digest only. For various reasons I need also non-digested version of some of the assets. Is there any easy way to enable back the old behavior? 回答1: The version of sprockets-rails used in Rails 4.0.0 no longer supports non-digest assets. Per sprocket-rails's

Heroku push error: “NameError: uninitialized constant Uglifier::VERSION” on rake assets:precompile

十年热恋 提交于 2019-12-08 18:53:57
问题 I'm receiving the following error when trying to push to production. Here's the result of the push: $ git push production master Counting objects: 124, done. Delta compression using up to 4 threads. Compressing objects: 100% (118/118), done. Writing objects: 100% (124/124), 19.73 KiB | 0 bytes/s, done. Total 124 (delta 66), reused 1 (delta 0) remote: Compressing source files... done. remote: Building source: remote: remote: -----> Ruby app detected remote: -----> Compiling Ruby/Rails remote:

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

╄→гoц情女王★ 提交于 2019-12-07 08:53:36
问题 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,

Access Asset Path from Rails Controller

一笑奈何 提交于 2019-12-07 06:22:34
问题 I'm sharing a configuration yml file client side, that I need to also load on the server side, I've placed it inside app/assets/javascripts/configuration.yml I can use #{asset_path 'configuration.yml'} inside a view to get the path, but I can't inside a controller. I could access directly using "#{Rails.root}/app/assets/javascripts/configuration.yml" but when deploying the filename gets the digest string appended. How can I get the same path from a controller? 回答1: ActionController::Base

ruby on rails: leaflet-rails not loading

不打扰是莪最后的温柔 提交于 2019-12-07 02:15:33
Using RoR 4.1.4 I am trying to use the leaflet-rails gem . I followed the steps outlined in the github page, but when I try to load the map, I see ReferenceError: L is not defined in the browser console. This obviously means that the helper from the gem is being loaded and executed but it can't find the leaflet.js file. However, the head section of the page shows that /assets/leaflet.js is being referenced and it actually IS there. When I look at the generated code: <div id="map"></div> <script> var map = L.map('map') map.setView([-54.0, 6.08], 16) L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/

Point Sprockets' `depend_on` directive to a non-assets file

拈花ヽ惹草 提交于 2019-12-07 00:50:02
问题 I have an app/assets/javascripts/moufa.js.erb file that gets populated with values from a config/moufa.yml file. I want to use the depend_on sprockets directive so that every time the yaml file gets changed, it recompiles the js file. 回答1: We were able to solve this by adding a new directive. This directive (put this in config/initializers/sprockets.rb) adds a dependency on a file in the config/ directory: class Sprockets::DirectiveProcessor def process_depend_on_config_directive(file) path =

Conditional require in Sprockets

眉间皱痕 提交于 2019-12-06 08:53:48
问题 How can I conditionally require assets using Sprockets? I've googled for solutions before asking and found this discussion in the Sprockets repository - Conditional require The solution discussed there is to use ERB: <% require_asset "#{ActiveScaffold.js_framework}/my_test" %> I've tried it this way: app.js.erb <% if debug == true %> <% require_asset "lib-debug" %> <% else %> <% require_asset "lib-min" %> <%end%> Rakefile def bundle_app(debug) env = Sprockets::Environment.new env.append_path

Dynamically render a sass file through sprockets

我只是一个虾纸丫 提交于 2019-12-06 03:17:54
问题 I want, from a helper, to render some variables in a .scss.erb template that makes use of the image-url() sass function: // template.scss.erb #<%= id %> { background-image: image-url('<%= image_file %>'); } So far, the ERB part has been easy: (leveraging this stack overflow answer) vars_binding = OpenStruct.new( id: 'foo', image_file: 'foo.jpg' ).instance_eval { binding } template = File.read('path/to/template.scss.erb') rendered_sass = ERB.new(template).result(vars_binding) Running that code

Compressing assets in Ruby on Rails 3

删除回忆录丶 提交于 2019-12-06 02:29:57
问题 I have following configurations in production.rb # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_assets = false # Compress JavaScripts and CSS config.assets.compress = true # Choose the compressors to use config.assets.js_compressor = :uglifier config.assets.css_compressor = :yui # Don't fallback to assets pipeline if a precompiled asset is missed config.assets.compile = true # Generate digests for assets URLs. config.assets.digest = true But