I changed a JS file under app/assets/javascripts but it is still the same. I deleted the file and re-created but the content is still the old one. This is my development.rb file:
App::Application.configure do
# Settings specified here will take precedence over those in config/application.rb
config.serve_static_assets = false
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = false
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
# Only use best-standards-support built into browsers
config.action_dispatch.best_standards_support = :builtin
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
config.action_mailer.delivery_method = :letter_opener
config.action_mailer.default_url_options = { :host => "lvh.me:3000" }
# Raise exception on mass assignment protection for Active Record models
# config.active_record.mass_assignment_sanitizer = :strict
# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
config.log_tags = [:uuid, :remote_ip]
end
The JS file is loaded inside the header tag with this code:
<script src="/assets/deals.js?body=1" type="text/javascript"></script>
which is the normal way JS is loaded in development
Try to clear precompiled assets:
bundle exec rake assets:clean
Try to delete the tmp folder and then restart the server - rails s.
That will do it.
bundle exec rake assets:clean and then bundle exec rake assets:precompile
Or delete the public/assets folder, and restart the app
Check for sprockets-rails gem
In my case I upgraded to Rails 7, and for some reason, the javascript files were not updated. Spent many hours trying to work out why.
I finally discovered the culprit - in my case - somehow, I had removed the sprockets-rails gem. I could have easily lost many months trying to figure this out.
I have similar issue in my app running Rails 6 and 7. When I add console.log into one of the javascript controllers there won't be any log in the browser console, and it looks like the console.log is not even there.
I have been having issue for quite some time and have not been able to pinpoint the exact reason, it might be due to bundler installed globally, conflict between rvm and asdf, config for overmind, yarn or npm. But I found the 3 commands that resolve this problem for some time and I usually run them one after another
rails assets:clobber
rake tmp:cache:clear
rake assets:precompile
Related
I just pulled down two new rails 3.2.6 projects that I have designated for some clean up. While attempting to make some UI changes I realized that even in development the asset pipeline was routing towards the public/assets folder.
After making some changes to the scss, I ran rake assets:clean followed by rake assets:precompile. Both ran without error and I restarted my localhost, and the styling was broken.
I've walked through the rails asset pipeline guide, as well as some other documentation that hasn't really provided the answer I need.
I attempted adding config.serve_static_assets = falseto the development.rb file in the config folder, however this as well did not render any scss.
Can anyone explain what is happening, and the best method of resolution?
Thanks
Add below statement to development.rb to prevent loading of files from public/assets.
config.serve_static_assets = false
Now restart the server, You will get better view.
To precomple the code in Test mode. -
Add this configuration to test.rb
config.assets.compile = false
config.serve_static_assets = true
I am working on a Rails 3 app and I need to get my js files in separate files on Heroku for debugging. On the local host when I run in development ENV it works fine.
On Heroku it serves the files separately and at the same time serves application.js with all the code in it, so the code is loaded twice which creates a lot of problems.
Things I tried:
1) Setting RACK_ENV and RAILS_ENV to 'development' in Heroku
2) Setting:
# Do not compress assets
config.assets.compress = false
# Expands the lines which load the assets
config.assets.debug = true
in both production.rb and development.rb
3) copying the entire content of development.rb to production.rb
4) using
<%= javascript_include_tag "application", debug: true %>
Nothing helps, I still get application.js with all the code and all the separate files at the same time.
You kind help will be very appreciated.
Thank you!
You can turn off rails asset pipeline by setting config.assets.enabled = false in config/application.rb
I have a rails app which compiles my stylesheets correctly in development. In production however, it doesn't.
I've tried to make the configuration values the same for my production config by setting
config.assets.compress = false
config.assets.compile = false
config.assets.digest = true
config.assets.debug = true
This does almost everything, it doesn't display the comments about where the css was compiled from like it does on development, and I haven't figured out how to enable that. My first question is how would I enable that in production for debugging?
Next - specificially using Spree 0.70.2, and what happens is in development the stylesheets from the gem are compiled. In production, they're being ignored. What could be the cause of this?
Is there a way to follow what's being compiled, a way to trace it (--trace when you run rake doesn't give you much relevant info)
Thanks
We're upgrading our app from Rails 2 to Rails 3.1, and I'm having trouble with the asset pipeline.
I've got the following in my config/application.rb:
if defined?(Bundler)
Bundler.require *Rails.groups(:assets => %w(development test))
# Bundler.require(:default, :assets, Rails.env)
end
# Enable the asset pipeline
config.assets.enabled = true
# config.assets.prefix = "/assets"
config.assets.paths << "#{Rails.root}/public/images"
config.assets.paths << "#{Rails.root}/public/stylesheets"
config.assets.paths << "#{Rails.root}/public/javascripts"
config.assets.version = '1.0'
And then this in development.rb
# Do not compress assets
config.assets.compress = false
config.assets.debug = true
I know this isn't the desired behavior for the pipeline, but we are doing it this way to make sure that when we merge the upgrade back into our master branch, all the old files are accounted for properly.
I then have the following file, "all.css," in my public/stylesheets directory:
/*
*= require ezform
*= require jquery-ui-1.8.9.custom
*= require thickbox
*= require yui-upload
*= require styles
*/
I am calling it from within my layouts/application.html.erb file like so:
<%= stylesheet_link_tag "all" %>
Loading things up in a browser, however, I get no styles (or javascript, for that matter). Firebug and Chrome tell me that the .css and .js files are being looked for in "/assets" - it's like the pipeline isn't searching through everything and bundling it like it should.
The error looks like this:
GET http://localhost:3000/assets/jquery-dependent.js 500 (Internal Server Error)
If I move "all.css" into /app/assets, it still won't find it. Moving it into /assets stops the error, but the stylesheet doesn't compile and I still don't get any styles in my browser.
There's also a slew of errors that look like this in my log:
Started GET "/assets/defaults.js?body=1" for 127.0.0.1 at 2011-12-22 14:35:36 -0600
[2011-12-22 14:35:36] ERROR NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
/Users/kevin/.rvm/gems/ruby-1.9.2-p0#media3/gems/rack-1.3.5/lib/rack/handler/webrick.rb:71:in `service'
/Users/kevin/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
/Users/kevin/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
/Users/kevin/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
cache: [GET /assets/defaults.js?body=1] miss, store
Served asset /defaults.js - 200 OK (1ms)
What am I missing?
sigh It was memcached. I tured it on (memcached -d) and now all my assets are appearing. I'm not sure why, so I'd love some explanation. Otherwise, it's working.
There are a while bunch of settings that need to be added into the development and application config files for the pipeline to work correctly.
Check out the last section of the pipeline guide for details of these.
Once you've done that I suggest that you change the manifest names to application.css and application.js as these are the default names and you'll run into fewer problems starting with those. Edit your question if it still does not work and I'll see if I can help after that.
I'm currently using Compass with Heroku using this configuration recommended on the Heroku knowledge base. Heroku has a read-only file system, and so the compiled stylesheets need to be stored in /tmp. This works fine remotely on Heroku; locally, however, Rails expects to find stylesheets in /public/stylesheets (when called through = stylesheet_link_tag 'screen.css', :media => 'screen, projection').
In order to solve the problem, I have created symbolic links in /public/stylesheets using ln -s tmp/stylesheets/screen.css public/stylesheets/screen.css and that seems to work.
Is there a way to solve this problem without using symbolic links, perhaps by changing some configuration in Rails? I've poked around without much success.
Here is my config/initializers/compass.rb:
require 'compass'
require 'compass/app_integration/rails'
Compass::AppIntegration::Rails.initialize!
# Required for Heroku:
require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets"))
Compass::AppIntegration::Rails.initialize!
Rails.configuration.middleware.delete('Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Rack::Static',
:urls => ['/stylesheets'],
:root => "#{Rails.root}/tmp")
And here is my config/compass.rb:
project_type = :rails
project_path = Compass::AppIntegration::Rails.root
# Set this to the root of your project when deployed:
http_path = "/"
# Necessary for Heroku (original commented out:
css_dir = 'tmp/stylesheets'
#css_dir = "public/stylesheets/compiled"
sass_dir = 'app/views/stylesheets'
environment = Compass::AppIntegration::Rails.env
Any help would be greatly appreciated.
I was actually just about to set up Compass with our Rails application, which is hosted on Heroku, so cheers for giving me an excuse to work through this. :)
The answer is simple:
Modify 'config/compass.rb':
project_type = :rails
project_path = Compass::AppIntegration::Rails.root
http_path = "/"
environment = Compass::AppIntegration::Rails.env
if environment == 'production'
css_dir = "tmp/stylesheets"
sass_dir = "app/views/stylesheets"
else
css_dir = "public/stylesheets"
sass_dir = "app/stylesheets"
end
Then modify 'config/initializers/compass.rb':
require 'compass'
require 'compass/app_integration/rails'
Compass::AppIntegration::Rails.initialize!
require 'fileutils'
FileUtils.mkdir_p(Rails.root.join("tmp", "stylesheets"))
environment = Compass::AppIntegration::Rails.env
if environment == 'production'
Compass::AppIntegration::Rails.initialize!
Rails.configuration.middleware.delete('Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Sass::Plugin::Rack')
Rails.configuration.middleware.insert_before('Rack::Sendfile', 'Rack::Static',
:urls => ['/stylesheets'],
:root => "#{Rails.root}/tmp")
end
... and voila, you're good.
ok, I'm a big heroku and compass fan myself so i've been through this many times
Heroku's docs, whilst giving correct information, provide poor advice in this instance.
When using compass, the best thing to do, 99.999% of the time is turn it off in production mode.
This means that you compile your stylesheets on your development machine and then add them to your git repo before pushing to heroku.
You will suffer a reasonably sizeable performance hit if you allow compass to compile on the server.
So here's what I do:
You should have a config.ru file at the base of your app. Open it and add the following:
require 'sass/plugin/rack'
use Sass::Plugin::Rack
Sass::Plugin.options[:never_update] = true
You can then remove quite a lot of the code from your initializer (especially the part where you unload Sass::Plugin::Rack). Additionally you will want to remove the if statement from compass.rb in config folder
Think about it, why would you want Sass to compile a stylesheet on the server? It just eats up processing power. Hope this helps,
EDIT::
PS - I should add that you will need to run compass watch from the command line now in order to get your stylesheets to compile in your dev environment
The recommended Heroku configuration will also work locally.
Removed the second 'Compass::AppIntegration::Rails.initialize!' from config/initializers/compass.rb, you only need it once.
Ensure your scss files are in 'app/views/stylesheets'
On both local and production servers the stylesheets will be compiled to tmp/stylesheets, and a request to /stylesheets will resolve to tmp/stylesheest. No need for two separate configurations.