Deploying Rails to Heroku on Windows, postrgres error - ruby-on-rails

Rails 3.2.1, Ruby 1.9.3
I can push my app to Heroku, but when I navigate to the page it fails. This is from the logs:
"Unexpected error while processing request: Please install the postgresql adapter: 'gem install activerecord-postgresql-adapter'"
I have already run that command locally and it worked.
I am using sqlite3 for dev, my gemfile looks like this:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'thin'
gem 'pg'
end
Any idea what I am doing wrong/how to fix this? thank you!

I'm getting the same sort of error with the same sort of config.
2013-04-05T08:06:12+00:00 app[web.1]: Connecting to database specified by DATABASE_URL
2013-04-05T08:06:12+00:00 app[web.1]: !! Unexpected error while processing request: Please install the postgresql adapte
r: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)
Have found that doing an update to the Gemfile (just adding whitespace) gets around the problem. It's a hassle though since it needs to be done every time any change is done.

Related

Build new Rails app Error loading the 'sqlite3' without evidently write verion

When generate new rails app, and start the server "rails s", first massage I got:
Puma caught this error: Error loading the 'sqlite3' Active Record adapter. Missing a gem it depends on? can't activate sqlite3 (~> 1.3.6), already activated sqlite3-1.4.0. Make sure all dependencies are added to Gemfile. (LoadError)
after reload a page:
ActiveRecord::ConnectionNotEstablished
No connection pool with 'primary' found.
def retrieve_connection(spec_name) #:nodoc:
pool = retrieve_connection_pool(spec_name)
raise ConnectionNotEstablished, "No connection pool with '#{spec_name}' found." unless pool
pool.connection
end
I reinstall ruby, rails, bundler, all except rvm
and I don't know what to do
P.S.
this error disappears when I evidently write sqlite3 verion, but it should work fine from a without it!!!
Help!What to do? or maybe reinstall all of it?
Try to add this on your Gemfile
gem 'sqlite3', '~> 1.3.6'
Instead of having only the SQLite3 without version.
It worked for me
To me, edit your Gemfile:
gem 'sqlite3', '~> 1.3.6'
and run this command:
bundle install
It works for me by adding sqlite3 version in the Gemfile.

Rails 5 is always checking for MongoDB adapter when I am not even using that Gem

I have just scaffolded a Rails 5 app but the gemfile does not have any Mongodb gem or even the database.yml file does not even have any mongoDB. But when i run 'rails s' command it always outputs an error
Could not load 'active_record/connection_adapters/mongodb_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.
Not able to understand how to even debug this as even google search does not point towards any meaningful solution
Any pointers would be greatly appreciated. Thank you in advance

LoadError: Could not load the 'listen' gem (Rails 5)

I've got an API mode Rails 5 app that won't let me run rake routes or rails s. The error I get is:
$ rake routes
rake aborted!
LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile
.../config/environment.rb:5:in `<top (required)>'
LoadError: cannot load such file -- listen
.../config/environment.rb:5:in `<top (required)>'
Tasks: TOP => routes => environment
(See full trace by running task with --trace)
I've verified that listen is in the development group in my Gemfile:
group :development do
gem 'listen', '~> 3.1.5'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
And that it's in my Gemfile.lock:
$ cat Gemfile.lock | grep 'listen'
listen (3.1.5)
spring-watcher-listen (2.0.0)
listen (>= 2.7, < 4.0)
listen (~> 3.1.5)
spring-watcher-listen (~> 2.0.0)
I've bundle updated, and bundle installed, and verified that gem install listen works. This was working earlier this week, but I'm not having luck going back through my commits.
$ ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin14]
I don't see it in vendor/cache but I'm not sure what to make of that...
$ bundle package | grep 'listen'
Appreciate the help!
Update:
I can "fix" the problem by putting gem 'listen', '~> 3.1.5' in the global Gemfile (and removing it from :development). Then all the errors go away and everything works, but that seems wrong.
If you are on rails 5 and you are using the default config/environments/development.rb file it will have this line of code in there.
config.file_watcher = ActiveSupport::EventedFileUpdateChecker
This requires the gem listen. This threw me for a bit as I was doing a rails 4 upgrades to a rails 5
edit:
Forgot to mention that if you comment that line of code out it will not need the listen gem anymore.
You might by mistake have set bundle install --without at some point, I sure did anyways.
To revert this run:
bundle config --delete without
I also ran bundle config --delete with as I manually set with option as well by mistake. Running both should get you back to default behaviour.
After having deleted the without config I could successfully run a bundle install again and afterwards my rails s, rails db:migrate etc. worked.
You can confirm if this is your issue by running bundle install and look at the second last line in the output. If it states:
Gems in the groups development and test were not installed.
It's for sure above solution should work for you.
I used this: bundle install --without development
Error:
Could not load the 'listen' gem. Add gem 'listen' to the development group of your Gemfile (LoadError)
After this, use that code:
bundle config --delete without
bundle config --delete with
Finally
bundle install
I'm posting this as an answer, but I don't like it.
I can "fix" the problem by putting gem 'listen', '~> 3.1.5' in the global Gemfile (and removing it from :development). Then all the errors go away and everything works, but that seems wrong.
I found an easy fix after a lot of trials of rebuild's
bundle config --delete without
bundle config --delete with
bundle install
If you accidentally built the gemset prior to seting your envirnoment correctly, then this may help clear out the problems.
I'm having the same problem by running rails c.
By reading this other Stack Overflow post I did realize that it is normal that both bundle exec rake command or rails console are running in a default production environment.
I figured I will solve the issue either by:
adding export RAILS_ENV=production in ~/.bash_profile
explicitly writing the environment in which I want the command to execute like bundle exec rake a_rake:task RAILS_ENV=production rails console --env=production etc...
I had similar problem today after upgrade from Rails 5.1.5 to 5.2.0. First time running the server there was the following 'missing assets' problem:
ActionView::Template::Error (The asset "asterisk_orange.png" is not present in the asset pipeline.)
Trying to precompile the assets shows the 'gem listen error':
$ bundle exec rake assets:precompile
rake aborted!
LoadError: Could not load the 'listen' gem. Add `gem 'listen'` to the development group of your Gemfile
My solution was to explicit set production environment:
$ RAILS_ENV=production bundle exec rake assets:precompile
This precompiles the assets w/o problems and the 'missing assets' problem was fixed.
I had the same issue. Thanks to #newdark answer I figured out the correct solution. Basically I wanted to deploy rails in production mode. But obviously forgot to set environment variable RAILS_ENV=production before running server.
So to recap, dependencies for production mode were installed while rails tried to start in development mode due to forgetting to set RAILS_ENV=production. If I went on to add gem listen to the production dependencies, I'd be running in development mode without being able to notice.
For me the solution was to do export RAILS_ENV=production before executing any rails commands and keep dependencies intact. Hope I managed to explain.
I had the same problem, i fix it by running
rails c -e production
I had same error when trying to generate mongoid database file.
but I created rails new project on ruby 2.5.1. Your ruby is 2.2. so the causality could be different in my situtation.
when I used rails new project, it was created in version 5.2, then I changed gem to 5.1.2 and problem arises. When I created with rails _5.1.6_ new in Gemfile there is generated additional pack for development.
group :development do
# Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'spring-watcher-listen', '~> 2.0.0'
end
this way 'listen' showed me in gemfile automaticaly
I was working with Docker and encountered this error when executing
rails webpacker:install
It was happening because this line was being executed before
ENV RAILS_ENV production
RUN chmod +x bin/rails
ENTRYPOINT ["bin/rails"]
Fixed it by simply placing all rails commands after this

Rails: steps to take before deploying rails app (e.g. changing database to postgres, etc)?

Hi I am about to deploy a rails app (onto heroku) I made and wanted to know what the procedure is. I know you have to change the database by changing gem 'sqlite3' to gem 'pg' but after I did that and went on my localhost:3000 it gives me the error:
ActiveRecord::ConnectionNotEstablished
What else am I missing?
You don't need to change gem. Database used in application on heroku default is postgres. Keep gem 'sqlite3' and add this in your Gemfile:
group :production do
gem "pg", "0.14.0"
end

why Heroku does not download database updates with 'Heroku db: pull'?

I have run 'heroku db:push' to download heroku db updates, it show me error:
taps load error: no such file to load --sqlite3
you may need to install or update the taps gem to use db commands.
on most systems this will be: sudo gem install taps
I have installed heroku 2.25.0, taps 0.3.24 and I changed the Gemfile replacing gem sqlite3 with:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
I think it's a problem of compatibility database between sqlite e postgresql.
is it possible? Or what can be ?
First, make sure you've got your gems all up to date by running bundle install. It won't hurt if everything's fine so you may as well make sure.
After that, you should be able to use db:pull to pull a copy to your local machine using the snippet that follows:
bundle exec heroku db:pull sqlite://local.db --app my_app
If this doesn't work for some reason, you can just change your Gemfile while pulling the database down -- and then you can change it back if you want to.
group :development, :test do
gem 'sqlite3'
# add this next line and run 'bundle install' until you get db:pull to work
gem 'pg'
end
group :production do
gem 'pg'
end
(I believe this will work, though I personally haven't tried it. Please respond if there's an issue.)
Finally, there are some issues pulling and pushing databases if you're running ruby 1.9.3 on your local machine -- but it's only if you're doing a db:push. If you have problems with that here's a link to the solution.
When you run the heroku command, it runs locally on your development machine. So the development group of your Gemfile is used:
group :development, :test do
gem 'sqlite3'
end
Since it contains sqlite3, you need the sqlite3 gem to be installed on your development machine. Have you run bundle install to install this gem locally? And you may need to run the heroku command within a bundle exec call to make sure the gems are loaded:
bundle exec heroku db:pull.
Finally, if you want to download Heroku DB, you should use db:pull, not db:push.

Resources