Tutorial demo_app won't work on heroku - ruby-on-rails

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.

Related

Deploying Ruby on Rails to Heroku

I am trying to upload RoR application to Heroku.
OS - Ubuntu, ruby version - 2.2.2p95, rails version - 4.2.1, database - PostgreSQL, installed RoR via BrightBox (Tutorial from treehouse), using git push heroku master to upload.
On the local server app works fine. When I push it to heroku, it gives out an error:
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
If you are the application owner check the logs for more information.
Log files say:
/usr/bin/env: ruby2.2: No such file or directory
I've tried all the possible variants, I could find on the Internet:
rake rails:update:bin
Remove bin from ~/.gitignore (But there is no such file)
heroku config:set PATH=bin:vendor/bundle/ruby/2.2.2/bin:/usr/local/bin:/usr/bin:/bin
Adding this to the GemFile: ruby '2.2.2'
Changed #!/usr/bin/env ruby2.2(.2 (not sure about ".2")) to #!/usr/bin/env ruby (in bin/rake, bin/bundle and bin/rails)
heroku run rails db:migrate
rake rails:update:bin
ln -s /usr/bin/nodejs /usr/bin/node
To upload to heroku, I've configured git, after that logged in heroku, after that "heroku create", after that "git push heroku master", then "heroku open"
And many others... Any ideas how to solve that problem?
Do you have the gem rails12_factor installed and config.assets.compile = true ?
Not sure you mistyped or something else. but heroku run rails db:migrate will not work it should be heroku run rake db:migrate . It might be because you don't have root page. Precompile issue etc.
Run heroku logs -a app_name to see actual logs.

Heroku assets precompile error, despite compiling assets locally

I am currently first time deploying my app to Heroku, and am encountering the precompile error. When I execute the command git push heroku master, I get:
Running: rake assets:precompile
rake aborted!
could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?
After a bit of searching, I encountered both Heroku's own troubleshooting guide on precompile error, as well as this post on precompile errors and Rails 3.2, and following their directions, did the following:
Added config.assets.initialize_on_precompile = false to my application.rb file
Made a new heroku app using heroku create just to be safe
Per the Rails guide, ran bundle exec rake assets:precompile
I thought that since I am doing the compiling locally, when pushing to Heroku it would just skip the compilation part based on detecting a manifest.yml file. However, even when I do so, when running git push heroku master, it will still run rake assets:precompile and generate the same error as seen above.
Thanks in advance for you help!
Addendum
In my .gitignore, I have the following:
# Ignore bundler config
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
At first glance, I would assume that it should work.
Can you confirm that you have committed and merged all changes into master? i.e. git status

Application Error rails app on heroku

I have uploaded my app to heroku, its a simple app to test a login, it uses a gem named sorcery, but when I test it on heroku, I get Application Error
To upload to heroku I only have do this sequence:
git init
git add .
git commit -m "init"
heroku create
heroku push heroku master
heroku rake db:migrate
I get this error:
rake aborted!
undefined method `sorcery' for
#<Rails::Application::Configuration:0x0000000266e660>
)
Please help me, I think that the gem sorcery is causing this problem, but I dont know what to do.
You can see the website here
Does this work on you localhost?
I see form your list of commands that
bundle install
is not there.
Make sure you have
gem "sorcery"
in your gem file
Then do
heroku login
and
bundle install
You'll probably get other errors. Go to Getting Started with Rails 3.x on Heroku and follow the instructions.

heroku run rake db:migrate failed: command not found

I'm a novie in heroku. When I was performing my CS169.1x homework2 (deploying an application) I ran into a problem with database filling using the following command: heroku run rake db:migrate. Here is terminal dump:
saasbook#saasbook:~/Documents/hw2_rottenpotatoes$ git pull heroku master
From heroku.com:afternoon-cove-7289
* branch master -> FETCH_HEAD
Already up-to-date.
saasbook#saasbook:~/Documents/hw2_rottenpotatoes$ git push heroku master
Everything up-to-date
saasbook#saasbook:~/Documents/hw2_rottenpotatoes$ heroku run rake db:migrate
heroku run rake db:migrate: command not found
saasbook#saasbook:~/Documents/hw2_rottenpotatoes$
What may be wrong? If there is error dump on heroku to check?
Have you installed the heroku gem? If you have heroku in the gemfile, you may need to do
bundle exec heroku run...
just to make sure you have heroku installed, what happens when you run:
$heroku help

Rails error 500, "We're sorry, but something went wrong"

After three evenings on this problem and reading all the posts about this, I have to ask this question finally!
I want to deploy the most simple Rails app to Heroku:
rails new test_appli
cd test_appli
git init
git add .
git commit -m "initial commit"
heroku create
git push heroku master
Everything's OK, the application works well on Heroku. After that, I'll create a SQLite3 database:
rails generate scaffold User name:string email:string
rake db:migrate
Everything's OK on the local machine. I can see localhost:3000/users well. Then I want to put the DB on Heroku. First I modify my Gemfile:
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
Then I send the whole thing to Heroku:
git init
git add .
git commit -m "with Database"
git push heroku master
heroku rake db:migrate
Then there are no errors in the batch, everything is OK, the DB is sent, but the page heroku.com/users gives the error
Rails 500, "We're sorry, but something went wrong"
I don't know more what to do. Can you help me?
I suspect you're trying to deploy a Rails 3.1 application to the bamboo stack (heroku create defaults to the 1.9.2 bamboo stack and doesn't run Rails 3.1 out of the box.). The Cedar stack is much better suited to Rails 3.1 sites -
try
heroku create --stack cedar
when creating your application on Heroku and repush it up. Also note your rake command on Heroku will become
heroku run rake db:migrate
Do:
heroku run rake db:schema:load
I had the same issue. It works for me after git push heroku master
Don't do the git init in the second set of commands - you only need to initialise your Git repo once.
Other than that this looks fine - are you seeing any errors anywhere?
Why would you use the pg gem in your production group, but the sqlite3 gem in your development group? Seems to me that your problem is likely due to the fact that you're developing with a different database then you're using in the production environment. If I were you, I would stick to one, which would make it much easier to debug.
If you really want/need to get the application running ASAP, then just run it in production with sqlite... Gemfile:
gem 'rails'
gem 'sqlite3'
Also, a quick way to figure out what the error is would be to run heroku logs from the unix console.
Which version of Rails?
Can you try creating the application running on the Cedar stack?
heroku create myapp --stack cedar
Given the application is running on cedar you need to modify the commands a bit, for example:
heroku run rake db:migrate
In any case you really need to checkout your logs, because your problem might not even be database related, but assets related.
Do you have the heroku shared 5mb database instance added?
When you create your heroku app (on cedar) it doesn't necessarily create the database automatically.
airlift:projects $ heroku create --stack cedar testapp9
Creating testapp9... done, stack is cedar
http://testapp9.herokuapp.com/ | git#heroku.com:testapp9.git
airlift:projects $ heroku addons --app testapp9
logging:basic
releases:basic
When you view your heroku config, you get nothing:
heroku config
airlift:projects $ heroku config --app testapp9
airlift:projects $
To add a database:
heroku addons:add shared-database:5mb
airlift:projects $ heroku addons:add shared-database:5mb --app testapp9
-----> Adding shared-database:5mb to testapp9... done, v3 (free)
airlift:projects $ heroku config
No app specified.
Run this command from an app folder or specify which app to use with --app <app name>
airlift:projects $ heroku config --app testapp9
DATABASE_URL => postgres://blah:blah#blah.compute-1.amazonaws.com/blah
SHARED_DATABASE_URL => postgres://blah:blah#blah.compute-1.amazonaws.com/blah
airlift:projects $
Then you should be able migrate your db.
Hey #redronin thanks for helping me find a way to connect to my postgres database on Heroku, however as a newbie to Heroku and postgresql I had to reverse engineer what "blah" was. So I figure I would break it down to help others as you helped me.
postgres://[user]:[password]#[servername].compute-1.amazonaws.com/[database]

Resources