Rails app points to 500.html page when uploaded to heroku - ruby-on-rails

I've created my stack on heroku and everything has been deployed but when I try to actually visit it via URL it just defaults to the 500.html error page. The app ran fine on my localhost, but I developed it in sqlite3. I've since changed my Gemfile to look like the following and ran bundle install.
#gem 'sqlite3'
gem 'thin'
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
When you visit the url it should be pointing to my login page.
This is what my database.yml file looks like...does this have anything to do with my problem.
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
Thanks for any advice

Use heroku logs to see the log file showing the 500 error's cause. If you haven't run your migrations that might be the cause. Be sure to run:
heroku run rake db:migrate
before you use your app.

Your database.yml file points to SQLite still. You'll need to change that to point to the PostgreSQL DB on heroku.

I can see from the comment that you are using sqlite for production into heroku. Which is not possible since heroku doesnt support sqlite. You can either use pg or mysql2 for your production environment. You can check here for solution :
How to configure database.yml for deployment to Heroku
And once you are done with it run these commands
heroku run rake db:reset
heroku run rake db:drop db:create db:seed
heroku run rake db:migrate

Related

heroku deploy error in RoR(Github deploy) what should I do with postgresql error?

I'm deploying small app from C9 to github then to Heroku!
In heroku deploy dashboard, it says it's been deployed, but when I open the app, it just gives me error msg.
So I searched a lot of Stackoverflow answers and was following the direction from Heroku website(https://devcenter.heroku.com/articles/sqlite3) to remove sqlite3 and install the gem pg.
I did replace gem 'sqlite3' to gem 'pg' and did 'bundle install', and then
It says I need to convert my config/database.yml file, So I replaced it like this:
development:
adapter: postgresql
database: my_database_development
pool: 5
timeout: 5000
test:
adapter: postgresql
database: my_database_test
pool: 5
timeout: 5000
production:
adapter: postgresql
database: my_database_production
pool: 5
timeout: 5000
and then when I come back to c9 bash and type 'rake db:create',
it shows me
**rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "my_database_development" does not exist**
this error.
someone said 'bundle exec rake db:setup' would work, so I did, and then it shows
**Couldn't create database for {"adapter"=>"postgresql", "database"=>"my_database_test", "pool"=>5, "timeout"=>5000}
/home/ubuntu/workspace/db/schema.rb doesn't exist yet. Run `rake db:migrate` to create it, then try again. If you do not intend to use a database, you should instead alter /home/ubuntu/workspace/config/application.rb to limit the frameworks that will be loaded.**
I don't know how to react to this msg.... when I type 'rake db:migrate' and it shows this again.
rake aborted!
ActiveRecord::NoDatabaseError: FATAL: database "my_database_development" does not exist
I'm not using database, so maybe I can try something on 'config/application.rb' file, but how should I do??
It wasn't necessary to change your development and test databases, those could still have used sqlite3 and so your C9 instance would have continued to work.
(Although there are some advantages to using a consistent adapter across all environments)
If this is just a hobby exercise I would be tempted to keep sqlite3 for development and test.
Also, Heroku replaces the database.yml with its own version so you don't need a production stanza in database.yml
You do need the pg gem, but you can specify it is only loaded in production and you can specify the sqlite3 gem is only loaded in development and test. Do that in your Gemfile and then bundle.
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
If you want to use PostgreSQL in your C9 instance, you have to install PostgreSQL (the database, not just the adapter). It's not a simple process.
This wiki explains how you would install it.
https://wiki.postgresql.org/wiki/Detailed_installation_guides
one of the solution that you can create database manually this is easily solut

Gem::LoadError: when trying to deploy on Heroku - Rails 4

I am trying to deploy an app (just a simple app from a Rails tutorial) to heroku but it keeps giving me the same error message. I use the command:
git push heroku master
It starts well, and then suddenly appears this error:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
Gem::LoadError: Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile.
I did bundle install already, everything went smooth there.
Here is my Gemfile:
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
Maybe something I am missing something on databse.yml file?
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
By the way, I don't know if it helps, but I am using Rails 4.0.4, Ruby 2.1.1 and the version of SQLite which comes already installed on Mac, which is 3.7.13
Kirti is right in saying that Heroku does not support sqlite as adapter,
do the following
in the Gemfile:
group :production, :staging do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
in database.yml
production:
adapter: postgresql
database: name_of_your_db
pool: 5
timeout: 5000
SQLite is not intended as a production grade database. Instead Heroku provides production grade PostgreSQL databases as a service.
Read the details SQLite on Heroku

Rails 4 - how to use sqlite3 in development and PostgreSQL in production w/Heroku

I am trying to deploy to Heroku but can't because the default sqlite3 server is still in place.
Detected sqlite3 gem which is not supported on Heroku.
https://devcenter.heroku.com/articles/sqlite3
In another tutorial with Rails 3.2.13 I was able to use sqlite3 as the dev db and Postgres as the production db. The Gemfile looks different in Rails 4 but I have modified it to have this:
group :development do
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
end
group :production do
gem 'pg'
end
I then changed my database.yml file so that the production section looked like this:
production:
adapter: postgresql
database: my_production_database
pool: 5
timeout: 5000
I then ran bundle install and rake db:create and rake db:migrate but am still unable to push to Heroku. So I tried rake db:drop as well as rake db:create and rake db:migrate but am still getting the same error message.
Am I missing something? What else do I need to do to make sure I'm getting Postgres as my production database and am able to use Heroku?
Don't do it. You are just going to run into problems down the road. Use the same database in production and development. There are a lot of resources available in documenting the switch from a sqlite to postgres database.
Take the time and switch.
Have a look at this Rails Cast.
http://railscasts.com/episodes/342-migrating-to-postgresql?view=asciicast
Try using this for your production DB
production:
adapter: postgresql
host: localhost
encoding: unicode
database: my_production_database
pool: 5
username:
password:
You can leave username and password blank

Rails app confused about environment?

I created a new Ruby on Rails app (first app I'm working on in Rails 3), and for some reason, my app seems to be confused about what environment it should be running in (unless I'm just confused).
When I run rake db:create, it's creating both the "myapp_development" and "myapp_test" databases. When I subsequently run rake db:drop, it drops the development database, but not the test database.
What's going on?
Edit 1: Here's what my database.yml file looks like:
development:
adapter: mysql
database: myapp_development
username: root
password:
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql
database: myapp_test
username: root
password:
production:
adapter: mysql
database: myapp_production
username: root
password:
Edit 2: Tried recreating a new app from scratch, and still have the same issue. Here's what I did.
1. Created a new rails app:
rails new myapp
2. Edited my Gemfile:
source 'http://rubygems.org'
gem 'rails', '3.0.6'
gem 'mysql', '2.8.1'
# Bundle the extra gems:
gem 'warden', '1.0.3'
gem 'devise', '1.2.1'
gem 'geokit'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
group :development, :test do
gem 'ruby-debug'
end
3. Edited my database.yml:
development:
adapter: mysql
database: myapp_development
username: root
password:
host: localhost
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: mysql
database: myapp_test
username: root
password:
host: localhost
production:
adapter: mysql
database: myapp_production
username: root
password:
host: localhost
4. Running rake db:create at this point creates both myapp_development and myapp_test. If I proceed to run rake db:drop followed by rake db:create, I get a command line warning stating "myapp_test already exists" since the drop only removes myapp_development, but the create attempts to create both dev and test databases.
It would only create the development and test databases if you ran rake db:create:all, not rake db:create. The latter will only create one or the other, depending on the environment you're working in.
check your
config/database.yml
file in your app for the database configuration, you probably want test around though. but database.yml will let you access everything. It will use the development db by default though then you specify when to use production
Also a note, just running rake db:migrate will create the databases if they don't exist and migrate your models, you might want to use that instead

"no such file to load -- pg" when trying rake db:create

The symptom of my problem is pretty simple:
$ rake db:create
(in /home/jason/projects/blog)
rake aborted!
no such file to load -- pg
(See full trace by running task with --trace)
I've already successfully run bundle install and gem install pg, so I don't know what else I might need to do.
Here's my `config/database.yml if it helps:
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password: foo
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password: foo
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
I figured it out. If I use pg instead of postgresql in my config/database.yml, it works.
Go to console and type below:
vim Gemfile
Inside the file commend the below:
- #gem 'sqlite3-ruby', :require => 'sqlite3'
Inside the file add the below:
- gem 'pg', :require => 'pg'
Problem Solved!!! :-) Enjoy!
One possibility is that the rake binary that you are running is from another ruby/gem environment and that it doesn't have access to the gems that you've installed.
If you have more than one version of ruby installed, try running which gem and then which rake to see if they are being run from the same bin directory. For example, on my machine both binaries are executed from bin directories under the same Ruby install:
/Users/scott/.rvm/rubies/ruby-1.9.2-p136/bin/gem
/Users/scott/.rvm/gems/ruby-1.9.2-p136/bin/rake
If you only have one ruby version installed on your system, then this isn't the answer!

Resources