If I run the following commands and then visit a page it gives an error about routing failure on an asset.
rake assets:precompile
rails s -e production
However if I do the same after the following commands where I've added RAILS_ENV=production everything works.
rake assets:precompile RAILS_ENV=production
rails s -e production
What is rake assets:precompile doing when I omit RAILS_ENV=production that explains why it is not working properly?
It is precompiling the assets in your default environment, which is more than likely developement
Related
I have an application in rails 4.2.7.1, when I run the db:migrate in test in works perfectly
➜ bundle exec rake db:drop RAILS_ENV=test
➜ bundle exec rake db:ceate RAILS_ENV=test
➜ bundle exec rake db:migrate RAILS_ENV=test
But when I ran it in development, only the last migration or beginning from a drop database after executing firs migration I get this:
➜ bundle exec rake db:migrate -- --trace
== 20191112204156 MyNewModel: migrating ==============================
-- create_table(:global_clients)
-> 0.0121s
== 20191112204156 MyNewModel: migrated (0.0122s) =====================
rake aborted!
SystemStackError: stack level too deep
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
I'm using ruby 2.1.6, and mysql 0.318 and later 0.4.10, I did rvm implode to start it again and nothing happens. I do not know how to solve it, even I do not know how to debug it. So any tips will be good.
It's a problem with dthe difference from rais test and development environments
When run the development mode, it works well:
$ rails s
But when the production mode:
$ RAILS_ENV=production rails s
And try to access it:
$ curl http://0.0.0.0:3000
Then message is:
Access denied.
There isn't any error log. Can't find what's the reason.
Make sure that you completed these steps before you ran rails s -e production.
bundle exec rake db:create RAILS_ENV=production
bundle exec rake db:migrate RAILS_ENV=production
bundle exec rake assets:precompile RAILS_ENV=production
then you can run: bundle exec rails s -e production
I'm working on deploy my rails application and I found that error always exists in my javascript file when I run RAILS_ENV=production bundle exec rails assets:precompile.But when I run rails assets:precompile to generate js file, it works well.Is there any differences between production and development in precompile phase? How can I solve this problem?
I think you don't have permission to generate compiled javascript file, to trace your error, run the following command:
RAILS_ENV=production bundle exec rails assets:precompile --trace
Solution of permission issue:
Try to run the command as sudo as the following:
sudo RAILS_ENV=production bundle exec rails assets:precompile --trace
I have this in lib/tasks/foo.rake:
Rake::Task["assets:precompile"].enhance do
print ">>>>>>>> hello from precompile"
end
Rake::Task["assets:precompile:nondigest"].enhance do
print ">>>>>>>> hello from precompile:nondigest"
end
When I run rake assets:precompile locally, both messages are printed.
When I push to heroku, only the nondigest message is printed. However, according to the buildpack, the push is executing the exact same command as I am locally.
Why does the enhancement to the base assets:precompile case not work on heroku but does work locally?
i've been looking into this issue and I found out that the behavior of the assets:precompile depending on if RAILS_ENV and RAILS_GROUPS are both set or not take a look at this locally.
# This works
→ bundle exec rake assets:precompile RAILS_ENV=production
>>>>>>>> hello from precompile:nondigest
>>>>>>>> hello from precompile
# This works
→ bundle exec rake assets:precompile RAILS_GROUPS=assets
>>>>>>>> hello from precompile:nondigest
>>>>>>>> hello from precompile
→
# This does not work :'(
→ bundle exec rake assets:precompile RAILS_ENV=production RAILS_GROUPS=assets
>>>>>>>> hello from precompile:nondigest
→
The problem comes from https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/sprockets/assets.rake in invoke_or_reboot_rake_task method if you replace the Rake::Task[task].invoke line with ruby_rake_task task then it works like you would expect it to. I've been poking around on exactly why this is, and haven't found the reason.
Since both variables are set in the Heroku build pack, you could create a custom build pack without setting both GROUP and ENV settings, though I think that is overkill. In this scenario you should be able to enhance assets:precompile:primary or assets:precompile:all and achieve an outcome similar to your desired intent.
Are you setting RAILS_ENV=production and RAILS_GROUPS=assets?
Also, according to this post, Heroku doesn't support custom asset compilation tasks...
I've got a new rails 3.1 site on Heroku and followed the instructions at this link http://devcenter.heroku.com/articles/rails31_heroku_cedar#troubleshooting about precompiling assets for a 3.1 application. It basically tells you to do this
RAILS_ENV=production bundle exec rake assets:precompile
and it worked for me. Yeah. However, I've decided to change a few images on the local site, and then pushed to Git and Heroku, but the images didn't appear on the Heroku site. I then tried to run this precompile command again but it didn't do anything on the site and I got this in the terminal... Any ideas?
/Users/me/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
/Users/me/.rvm/gems/ruby-1.9.2-p290#devise311/bin/rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
/Users/me/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
/Users/me/.rvm/gems/ruby-1.9.2-p290#devise311/bin/rake assets:precompile:nondigest RAILS_ENV=production RAILS_GROUPS=assets
for some reason it's working now if I just do a regular git push.
I always run RAILS_ENV=production bundle exec rake assets:precompile right before I push to my heroku remote. Is that what you did?