asset-pipeline

Full Asset URL in a Rails .js.erb file

血红的双手。 提交于 2019-12-09 12:16:13
问题 I have a bookmarklet that can be loaded on any website. It works like this; loads http://my.example.com/assets/bookmarklet.js includes http://my.example.com/assets/bookmarklet.css The css file is added to the dom via bookmarklet.js , so it needs to know where this is. My code is as follows; // assets/javascripts/bookmarklet.js.erb var config = { stylesheetUrl: '<%= asset_path("bookmarklet.css", :only_path => false) %>' } But no matter what I try this renders as var config = { stylesheetUrl: '

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

Ruby on Rails 4 javascript not executed

蹲街弑〆低调 提交于 2019-12-09 06:40:07
问题 I have a custom js file in app/assets/javascripts . This is the js file: //app/assets/javascripts/contacts.js //$(document).ready(function() { //I've already tried with this method $(window).load(function() { alert("foo bar") }); I require the file contacts.js file in the application.js file. If I inspect the html page I see the js file loaded correctly, but the message is not shown. If I reload the page (by pressing f5), the message is correctly show. When the page is loaded the javascript

Heroku always runs assets:precompile with the production environment for Rails 3.2

倾然丶 夕夏残阳落幕 提交于 2019-12-09 05:34:50
问题 I have my Heroku environment set to staging but my assets are always compiled in the production environment. Here's heroku config : GEM_PATH => vendor/bundle/ruby/1.9.1 LANG => en_US.UTF-8 PATH => bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin RACK_ENV => staging I've added an exception to the production.rb file so I know which env it's running when compiling the assets. The server starts up just fine running heroku run console shows that I'm running staging. It's just when

Rails image disappears with error: Failed to load resource: net::ERR_CONTENT_LENGTH_MISMATCH

。_饼干妹妹 提交于 2019-12-09 05:27:56
问题 Essentially my problem is that a page loads fine and looks normal. After about 30 seconds it suddenly disappears. Here's the server log before the error (as loading the page): Started GET "/" for 127.0.0.1 at 2014-03-11 23:53:30 -0400 Processing by PagesController#home as HTML Rendered pages/home.html.erb within layouts/application (0.7ms) Rendered layouts/_head.erb (3.3ms) Rendered layouts/_header.erb (0.9ms) Rendered layouts/_footer.erb (0.2ms) Completed 200 OK in 11ms (Views: 10.5ms)

How can I run SOME initializers when doing a Rails assets:precompile?

给你一囗甜甜゛ 提交于 2019-12-09 04:21:40
问题 Background I have an app that I recently updated to Rails 3.2.1 (from Rails 3.0.x) and have refactored the JS and CSS assets to make use of the new asset pipeline. The app is hosted on Heroku with the Celadon Cedar stack. App Config I keep application specific configuration in a YAML file called app_config.yml and load it into a global APP_CONFIG variable using an initializer: # config/initializers/load_app_config.rb app_config_contents = YAML.load_file("#{Rails.root.to_s}/config/app_config

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

How to display controller specific javascript in rails 3.1?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 23:32:16
问题 I have my assets folder structure like this assets javascripts products --product.js --productValidate.js store --store.js I want the project.js and projectValidate.js to be added in my application.js as a part of asset pipe-lining only when actions in product controller is called and store.js when actions in store controller is called. How can i achieve this in rails 3.1? 回答1: As Rahul already mentioned, application.js is precompiled and the same for every action. So it does not depend on a

Images desapears after deploy Rails 3.1.3 on Heroku Cedar

人盡茶涼 提交于 2019-12-08 19:52:32
After deploy on heroku cedar, images desapear. I've a CSS like : :css /* */ table.table thead .sorting { background: url('assets/datatables/sort_both.png') no-repeat center right; } table.table thead .sorting_asc { background: url('assets/datatables/sort_asc.png') no-repeat center right; } table.table thead .sorting_desc { background: url('assets/datatables/sort_desc.png') no-repeat center right; } /* */ table.table thead .sorting_asc_disabled { background: url('assets/datatables/sort_asc_disabled.png') no-repeat center right; } table.table thead .sorting_desc_disabled { background: url(

Rails: Is it possible to get the controller and action name from an asset file?

微笑、不失礼 提交于 2019-12-08 18:50:44
I want to do something like this in my asset pipeline: application.js //= require jquery //= require jquery_ujs //= require_tree ./includes //= require global <% if File.exists? "#{Rails.root}/assets/javascripts/#{params[:controller]}.js" %> //= require <%= params[:controller] %> <% end %> <% if File.exists? "#{Rails.root}/assets/javascripts/#{params[:controller]}/#{params[:action]}.js" %> //= require <%= params[:controller] %>/<%= params[:action] %> <% end %> Now this doesn't work because the assets files cannot access params variable. Now is there a way to grab what the current controller