Access Asset Path from Rails Controller
ActionController::Base.helpers.asset_path(“configuration.yml”) Might also be good to put configuration.yml in a different folder to separate javascript from non-javascript files.
ActionController::Base.helpers.asset_path(“configuration.yml”) Might also be good to put configuration.yml in a different folder to separate javascript from non-javascript files.
You have two possible structure : the first one and the second one. With both following examples, you expose a package at /assets/externals.js. You can javascript_include_tag this package, but you can also require it in your application.js file. The first one vendor/ ├── assets │ ├── javascripts │ │ ├── externals.js │ │ ├── modernizr-1.7.js … Read more
config.assets.precompile = [‘*.js’, ‘*.css’] That will compile any JavaScript or CSS in your asset path, regardless of directory depth. Found via this answer.
I’ve discovered a way to make it less rigid and future proof by still using the asset pipeline but having the stylesheets grouped. It’s not much simpler than your solution, but this solution allows you to automatically add new stylesheets without having to re-edit the whole structure again. What you want to do is use … Read more
To load only the necessary name_of_the_js_file.js file: remove the //=require_tree from application.js keep your js file (that you want to load when a specific page is loaded) in the asset pipeline add a helper in application_helper.rb def javascript(*files) content_for(:head) { javascript_include_tag(*files) } end yield into your layout: <%= yield(:head) %> add this in your view … Read more
Place the following code in config/initializers/quiet_assets.rb if Rails.env.development? Rails.application.assets.try(:logger=, Logger.new(‘/dev/null’)) Rails::Rack::Logger.class_eval do def call_with_quiet_assets(env) previous_level = Rails.logger.level Rails.logger.level = Logger::ERROR if env[‘PATH_INFO’] =~ %r{^/assets/} call_without_quiet_assets(env) ensure Rails.logger.level = previous_level end alias_method_chain :call, :quiet_assets end end Updated: It now works for Ruby on Rails 3.2 too (previous attempt fixes before_dispatch, and now we’re going for the … Read more
The Asset Pipeline docs suggest how to do controller-specific JS: For example, if a ProjectsController is generated, there will be a new file at app/assets/javascripts/projects.js.coffee and another at app/assets/stylesheets/projects.css.scss. You should put any JavaScript or CSS unique to a controller inside their respective asset files, as these files can then be loaded just for these … Read more