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?
Related
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 did the following steps for deploying app and migrating my database:
git add -A
git commit -m "add changes"
git push heroku master
heroku run rake db:migrate
In console I see next:
Running `rake db:migrate` attached to terminal... up, run.9234
== 20150713191218 CreateMovies: migrating =================
-- create_table(:movies)
-> 0.0379s
== 20150713191218 CreateMovies: migrated (0.0381s) ============
heroku restart
But heroku run rake db:migrate does not work. When I run my app, my database is empty. I don't understand why. I don't see any errors.
And I'm sorry, that I repeat this question. I saw that people already asked about this problem, but no advice helped me.
try heroku run rake db:migrate RAILS_ENV=production
To populate your database automatically with rake task you need to use the command RAILS_ENV=production rake db:seed(this will populate your production database) and have a seed file in place. But I guess that was not really what you were looking for
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
I execute
$ heroku run rake assets:clean
Running `rake assets:clean` attached to terminal... up, run.2
/usr/local/bin/ruby /app/vendor/bundle/ruby/1.9.1/bin/rake assets:clean:all RAILS_ENV=production RAILS_GROUPS=assets
rm -rf /app/public/assets
But it doesn't look like it is working due I can access to the assets by http request and also if I open a heroku console I can see the files:
$ heroku run console
irb(main):013:0> Dir.glob "./public/assets/*"
=> ["./public/assets/img", "./public/assets/application.js.gz", "./public/assets/application.js", "./public/assets/rails.png", "./public/assets/manifest.yml", "./public/assets/application.css", "./public/assets/assets", "./public/assets/application.css.gz"]
I need to remove the assets because they are producing conflicts with my new configuration.
The rake assets:clean functionality has been replaced with
rake assets:clobber
in the latest version of Rails.
https://github.com/rails/sprockets-rails/blob/master/README.md
I had to do:
heroku repo:purge_cache
and wait a bit. rake assets:clobber did not work for me, even though it printed:
INFO -- : Removed /app/public/assets
rm -rf /app/tmp/cache/assets]
if you run the heroku command and get:
! `repo:purge_cache` is not a heroku command.
! See `heroku help` for a list of available commands.
install the command in your heroku toolbelt with:
heroku plugins:install https://github.com/heroku/heroku-repo.git
and rerun.
I'm trying to run the chapter two demo_app from the Ruby on Rails 3 Tutorial book on Heroku and it is not working. gws-demp-app.heroku.com gives the default Rails page, but gws-demo-app.heroku.com/users gives a web page that says "We're sorry, but something went wrong." On my desktop it works fine. I'm using the tools from RailsInstaller.org.
I had problems with heroku rake db:migrate at the end of the chapter not finding the activerecord-postgresql-adapter so I did install gem pg, bundle install, and updated the Gemfile and repositories. Everything is on github at https://github.com/gwshaw/demo_app.
What looks like the same problem appears at https://stackoverflow.com/questions/7619551/heroku-rake-dbmigrate-success-but-not-showing-in-app
I tried heroku restart recommended there, but that causes: Restarting processes... C:/RailsInstaller/Ruby1.9.2/lib/ruby/1.9.1/net/http.rb:6
44:in `initialize': getaddrinfo: No such host is known. (SocketError)
I tried what is claimed to work, precompiling assets with bundle exec rake assets:precompile, but that generates an error: C:/RailsInstaller/Ruby1.9.2/bin/ruby.exe C:/RailsInstaller/Ruby1.9.2/bin/rake as
sets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
rake aborted!
TypeError: Object doesn't support this property or method
(in C:/Sites/rails_projects/demo_app/app/assets/javascripts/application.js)
I'm new to ruby and rails so I'm at a loss. Any ideas?
Solved below.
Yes , this worked for me too after installing the pg gem, I ran the following:
bundle exec rake assets:precompile
git add .
git commit -am "add a note reflecting changes made"
git push
heroku create
git push heroku master
heroku rake db:migrate
heroku db:push
after invoking these commands, I was able to successfully open the demo_app on heroku.
Thanks for your post — I'm new to Rails, but reading your post helped me with a very similar issue.
Here's what worked for me:
Install pg gem to use postgreSQL on Heroku: (related article)
sudo gem install pg
Install taps gem to allow push of your local database to Heroku: (related article)
gem install taps
then the following sequence…
bundle exec rake assets:precompile
git add .
git commit -am "add a note reflecting changes made"
git push
heroku create
git push heroku master
heroku rake db:migrate
heroku db:push
If you're still having trouble, these articles are helpful too:
Stack Overflow - Heroku command: Heroku Rake db:migrate fails
Heroku - Getting Started with Rails 3.0 on Heroku/Cedar
The problem with bundle exec rake assets:precompile was the key and is solved here RoR Precompiling Assets fail while rake assets:precompile - on basically empty application.js
Oddly, Heroku wouldn't automatically precompile the assets on a git push heroku and thus would not find them. I don't think this little demo_app even uses assets, so that may be why it didn't precompile, but it still could not find applicaiton.css and failed. Once I set config.log_level = :debug in production.rb, I could see the problem in the logs. With the precompile working due to the above fix, everything worked.