Default_url in Paperclip Broke with Asset Pipeline Upgrade
:default_url => ActionController::Base.helpers.asset_path(‘missing_:style.png’) Then put the default images in app/assets/images/
:default_url => ActionController::Base.helpers.asset_path(‘missing_:style.png’) Then put the default images in app/assets/images/
When testing locally your production environment, you have to compile the assets locally. Simply run the command below: RAILS_ENV=production bundle exec rake assets:precompile It will generate all the assets under public/assets. Next, you have to tell Rails to serve the assets itself. Server software (eg. Nginx or Apache) do it for you on environments like … Read more
Adding config.serve_static_assets = false to development.rb will prevent loading files from /public/assets. Actually I need to precompile locally because my test mode is using only static assets from /public/assets – tests are catching possible production asset problems. How? Just set config.assets.compile = false and config.serve_static_assets = true in test.rb configuration.
config.assets.precompile accepts regular expressions and wildcard matching – so to ensure all js files get compiled, without specifying each by name, something like this should do the trick: config.assets.precompile << ‘*.js’
UPDATE: Now there is a gem that does this for you: js-routes The problem is that Sprockets is evaluating the ERB outside of the context of your Rails app, and most of the stuff you’re expecting isn’t there. You can add things to your Sprockets context like so: Rails.application.assets.context_class.class_eval do include Rails.application.routes.url_helpers end That’s all … Read more
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
In rails 4 you need to make the changes below: config.assets.compile = true config.assets.precompile = [‘*.js’, ‘*.css’, ‘*.css.erb’] This works with me. use following command to pre-compile assets RAILS_ENV=production bundle exec rake assets:precompile Best of luck!
The problem with CSS is, you do not want to automatically add all files. The order of which your sheets are loaded and processed by the browser is essential. So you will always end up explicitly importing all your css. As an example, lets say you have a normalize.css sheet, to get a default look … Read more
I just had this issue myself. 3 points that will hopefully help: If you place images in your app/assets/images directory, then you should be able to call the image directly with no prefix in the path. ie. image_url(‘logo.png’) Depending on where you use the asset will depend on the method. If you are using it … Read more
You can include any helper/module/class in an erb template with: <% environment.context_class.instance_eval { include MyHelper } %> See: https://github.com/rails/sprockets/blob/master/lib/sprockets/environment.rb and https://github.com/rails/sprockets/blob/master/lib/sprockets/context.rb To use the url helpers you have to include your specific applications’ helpers. They are available at Rails.application.routes.url_helpers so: <% environment.context_class.instance_eval { include Rails.application.routes.url_helpers } %> EDIT: Fixed links to moved sprockets repo but … Read more