So there a couple of similar questions regarding this but I've tried all of the answers and still can not get my app to do simple logging.
I'm using Rails 4.2, Ruby 2.2, Puma on a Heroku free account; So far I've tried:
Adding config.logger = Logger.new(STDOUT), config.log_level = :debug, and config.logger.level = Logger::DEBUG to my production.rb file as specified here, here and here
Adding the rails_12factor gem as specified by Heroku here
Added ActiveRecord::Base.logger.level = Logger::DEBUG to my environment.rb file as outlined here
Added $stdout.sync = true to my config.ru file as outlined here
In my app I have the following (none of which I can see in production when using $ heroku logs --tail nor in papertrail)
Rails::logger.debug "Test of 'Rails::logger.debug' logging"
Rails.logger.debug "Test of 'Rails.logger.debug' logging"
puts "Test of 'puts' logging"
So the problem was actually that I accidently had two classes with the same name; Apparently ruby doesn't doesn't throw an error in that event and because config.eager_load is set to false in dev, it always worked. The app always ended up loading the class without logging in production first which is why I never saw any messages.
If you're on a local environment. This worked for me.
Create a Heroku account. Install Heroku Toolbelt.
From your terminal run heroku login, youll be be prompted qith your username and password, enter your credentials.
In Gemfile, add the pg gem to your Rails project. Change:
gem sqlite
to
gem 'sqlite3', group: :development
gem 'pg', '0.18.1', group: :production
In Gemfile, add the rails_12factor gem::
gem 'rails_12factor', group: :production
In the terminal, install the gems specified in the Gemfile:
$ bundle install
Ensure config/database.yml is using the postgresql adapter. Change:
production:
<<: *default
database: db/production.sqlite3
to
production:
<<: *default
adapter: postgresql
database: db/production.sqlite3
Commit your changes to git:
$ git add .
$ git commit -m "Heroku config"
In the terminal, create an app on Heroku:
$ heroku create
Push your code to Heroku:
$ git push heroku master
If you are using the database in your application, migrate the database by running:
$ heroku run rake db:migrate
It has worked well for me. I am on windows.
Related
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
I'm trying to deploy my first app to Heroku. I'm using SQLite as the database. As far as I know Heroku doesn't use SQLite - it switches to Postgres in the backend.
When I'm deploying I get the following error:
/usr/ruby1.8.7/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in
`require': no such file to load --
sqlite3 (LoadError)
My Gemfile (which is what I assume is causing this problem) looks as follows:
source 'http://rubygems.org'
gem 'rails', '3.0.0'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
What am I doing wrong?
Heroku doesn't support SQLite databases. You need to use PostgreSQL on production, as I also explained in this post.
group :production do
gem "pg"
end
group :development, :test do
gem "sqlite3", "~> 1.3.0"
end
Actually, it's recommended to use in development/test an environment as close as possible to production. Therefore, I suggest you to switch all your environments to PostgreSQL.
# replace gem "sqlite3" with
gem "pg"
Simone Carletti is correct and so is Joost. You only need to group the sqlite3 gem or remove it entirely from your Gemfile. Heroku just needs to know that you don't want to use sqlite3 for production
So this:
...
group :development, :test do
gem "sqlite3-ruby", "~> 1.3.0", :require => "sqlite3"
end
...
Or this:
...
#No reference to sqlite3-ruby
...
If you remove the reference entirely you will probably mess up your local db though
After banging my head against this problem, I realized I was pushing the master branch of my repo to heroku, while I was making all of my postgres changes in my deploy-postgres branch of my repo!
I merged my deploy-postgres branch with my local master [git checkout master; git merge deploy-postgres] and then could run git push heroku master as per the heroku documentation.
I was stuck on this for hours looking at every answer here, but I couldn't get enough details to make it come together. This paged walked me through everything. http://railsapps.github.io/rails-heroku-tutorial.html
Good luck.
i was facing similar issue, but I realized that I was on a different branch - new_layout and was pushing master.
So I pushed my desired branch to heroku using following command and everything worked fine.
git push heroku new_layout:master
You can use clearDB addon
and gem 'mysql2' instead of gem 'sqlite3'
I'm using sqlite3 and deploy to Heroku no problem. Here is my database.yml
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
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
i have a remote SQLSERVER instance wich i want to connect from my rails app hosted on heroku.
My gemfile:
gem 'activerecord-sqlserver-adapter', '~> 3.2.12'
gem 'tiny_tds'
database.yml
production:
adapter: sqlserver
mode: dblib
dataserver: host.database.windows.net
database: items
username: username#host
password: password
azure: true
production.rb
dbconfig = YAML.load(ERB.new(File.read(File.join("config","database.yml"))).result)
ActiveRecord::Base.establish_connection dbconfig['production']
But i get the follwing error during the deploy process:
Writing config/database.yml to read from DATABASE_URL
Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
LoadError: Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (sqlite3 is not part of the bundle. Add it to Gemfile.)
It seems that Active record require sqlite3 but if i have tiny_tds it should use sql server.
In development env all works fine.
Sure there is something i am missing.
UPDATE
I've already set up the custom buildpack
BUILDPACK_URL: https://github.com/firmhouse/heroku-buildpack-ruby-freetds.git
and the DATABASE_URL config var.
UPDATE 2
Making a pp of dbconfig var while deploing display this
{"production"=>
{"adapter"=>"sqlite3",
"database"=>"dbname",
"username"=>"user",
"password"=>"pass",
"host"=>"127.0.0.1"}}
It seems that heroku overwrite my database.yml file, any suggestions?
UPDATE 3
I have set DATABASE_URL=sqlserver//user:pass#host:1433/database is this wrong?
I've faced same issue and finally found the answer.
You have to put the suffix below:
?encoding=uft-8&azure=true
So, your database_url will be like this:
sqlserver://[user]:[password]#[server.database.windows.net]:1433/[database]?encoding=uft-8&azure=true
Hope it helps
Looks like you need to use a custom buildpack.
Using this FreeTDS buildpack on Heroku
To use this buildpack you can pass in an option when creating your Heroku app:
heroku create my_new_sqlserver_app --buildpack https://github.com/firmhouse/heroku-buildpack-ruby-freetds.git
Or for current apps:
heroku config:add BUILDPACK_URL=https://github.com/firmhouse/heroku-buildpack-ruby-freetds.git
Configuring your database connection
After creating your app or setting up your existing app to use the buildpack, you need to modify the DATABASE_URL config variable to point to your sqlserver instance. We currently use a SQL Server 2008 Express edition:
heroku config:add DATABASE_URL=sqlserver://username:password#sqlserver_host:1433/database_name
I just tried to deploy my Rails 4.1.0 app to Heroku, but I get this error:
Gem::LoadError: Specified 'sqlite3' for database adapter, but the gem is not loaded.
...
error: failed to push some refs to 'git#heroku.com:somedomain.git'
For the moment I don't use any database in production.
In my Gemfile, I made the sqlite3 gem only work for development mode like this:
gem 'sqlite3', group: :development
But this doesn't solve the issue.
Does anybody know how I can deploy my Rails 4.1.0 app to Heroku without specifying a database for production?
Thanks for your help,
Anthony
Its better to use pg gem for heroku.
Your config/database.yml should look this way
production:
adapter: postgresql
encoding: unicode
database: appname_production
pool: 5
username: user
password:
Gemfile
gem 'pg'
This works for heroku in a some of my apps.
I'm trying to deploy my first app to Heroku. I'm using SQLite as the database. As far as I know Heroku doesn't use SQLite - it switches to Postgres in the backend.
When I'm deploying I get the following error:
/usr/ruby1.8.7/lib/ruby/gems/1.8/gems/bundler-1.0.0/lib/bundler/runtime.rb:64:in
`require': no such file to load --
sqlite3 (LoadError)
My Gemfile (which is what I assume is causing this problem) looks as follows:
source 'http://rubygems.org'
gem 'rails', '3.0.0'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
What am I doing wrong?
Heroku doesn't support SQLite databases. You need to use PostgreSQL on production, as I also explained in this post.
group :production do
gem "pg"
end
group :development, :test do
gem "sqlite3", "~> 1.3.0"
end
Actually, it's recommended to use in development/test an environment as close as possible to production. Therefore, I suggest you to switch all your environments to PostgreSQL.
# replace gem "sqlite3" with
gem "pg"
Simone Carletti is correct and so is Joost. You only need to group the sqlite3 gem or remove it entirely from your Gemfile. Heroku just needs to know that you don't want to use sqlite3 for production
So this:
...
group :development, :test do
gem "sqlite3-ruby", "~> 1.3.0", :require => "sqlite3"
end
...
Or this:
...
#No reference to sqlite3-ruby
...
If you remove the reference entirely you will probably mess up your local db though
After banging my head against this problem, I realized I was pushing the master branch of my repo to heroku, while I was making all of my postgres changes in my deploy-postgres branch of my repo!
I merged my deploy-postgres branch with my local master [git checkout master; git merge deploy-postgres] and then could run git push heroku master as per the heroku documentation.
I was stuck on this for hours looking at every answer here, but I couldn't get enough details to make it come together. This paged walked me through everything. http://railsapps.github.io/rails-heroku-tutorial.html
Good luck.
i was facing similar issue, but I realized that I was on a different branch - new_layout and was pushing master.
So I pushed my desired branch to heroku using following command and everything worked fine.
git push heroku new_layout:master
You can use clearDB addon
and gem 'mysql2' instead of gem 'sqlite3'
I'm using sqlite3 and deploy to Heroku no problem. Here is my database.yml
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
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