0

I precompiled assets on my dev environment (by mistake!) now any changes done on js/css files are not reflecting on browsing site locally. I removed assets folder from public directory but then no css/js was available. How do I get rid of this? As a temporary solution I just cloned project into new directory and it works.

pramodtech
  • 6,300
  • 18
  • 72
  • 111

3 Answers3

0

In case if I understood you correctly, generally, when you precompile by default assets directory is being created inside public directory. To get your assets back, you can precompile again.

There is also a cache in tmp directory that you might consider removing.

Later you could use a $ (bundle exec) rake assets:precompile in combination with $ (bundle exec) rake assets:clean instead of $ rm -r public/assets so that new assets would be in effect rake way.

A one line command to look at new changes after your commits in environment would be

$ RAILS_ENV=(environment) rake assets:clean assets:precompile

but generally in development assets are not meant to be served as in production mode, so running previous with RAILS_ENV=production and starting a local server in production mode would be considered as a way to check (but not to make sure) if your assets would be served upon deployment in real production.

dachi
  • 1,604
  • 11
  • 15
  • Once I clean it, I don't need to precompile it again, right? – pramodtech Mar 05 '14 at 05:30
  • Look at it as: Code, Clean, Precompile, Look.. Code, Clean, Precompile, Look.. Code, Clean, Precompile, Look.. – dachi Mar 05 '14 at 06:01
  • I do not want to precompile for every change done in js. How do I get rid of this? I want it back to normal way where I change js and with refresh of page it is reflected on page. – pramodtech Mar 05 '14 at 08:55
  • It's not a good idea because http://stackoverflow.com/questions/8821864/config-assets-compile-true-in-rails-production-why-not but you can change `config.assets.compile = false` to `config.assets.compile = true` in `config/environments/production.rb` – dachi Mar 05 '14 at 11:59
  • I am talking about development environment, for production I will definitely use precompile. – pramodtech Mar 05 '14 at 12:31
  • Then you should remove directory `assets` in `public` if it exists, then start server in development mode. `$ rails server -e development` if it's not `development` by default in your configuration, otherwise `$ rails s`. In development mode you don't use `assets:precompile` – dachi Mar 05 '14 at 12:34
  • @pramodtech please let us know if we could not resolve your issue so we can expand our answers further to help you. – dachi Mar 08 '14 at 08:39
0

The question is: why do you need asset precompilation in the development environment? It's not meant to work like this.

The asset pipeline allows working in development with the uncompressed, unminified versions of your JS files. It also reloads them each time you refresh your browser, so you can develop your application with ease.

In production, though, the asset pipeline precompiles the JS files / assets you have into one single, minified file. This allows for better performance on the client as the files are smaller and are fetched in one single request.

So precompiling assets in development makes no sense at all.

yagooar
  • 15,959
  • 6
  • 20
  • 21
  • Yes, I understand that assets precompile is not meant for development. I did it by mistake. How do I undo this and make it work normally as earlier it used to. – pramodtech Mar 05 '14 at 05:29
0

I went into the exact same problem and resolved it following @dashi's advice: 'remove directory assets in public, then start server in development mode.' everything is back to normal.

modern box
  • 1
  • 1
  • 1
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31368726) – 273K Mar 30 '22 at 14:17