Rails Heroku application error - heroku

I try to push my rails application to heroku but encountered the following error
Application Error
An error occurred in the application and your page could not be served. Please try again in a few moments.
If you are the application owner, check your logs for details.
Because I am using sqlite3
A search on the web show I should do the following
heroku rake db:create
heroku rake db:migrate
the heroku rake db:create failed by complaining
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.)
The command gem install activerecord-postgresql-adapter failed and complains
ERROR: Could not find a valid gem 'activerecord-postgresql-adapter' (>= 0) in any repository
ERROR: Possible alternatives: activerecord-postgis-adapter, activerecord-jdbcpostgresql-adapter, activerecord-postgresql-cursors, activerecord-jdbcmysql-adapter, activerecord-jdbcmssql-adapter
Then I searched the web again and followed the http://devcenter.heroku.com/articles/how-do-i-use-sqlite3-for-development suggestion to change
gem 'sqlite3'
to
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
and run
bundle install --without production
however this did not solve the problem
another source say I need to do like
group :production do
gem 'therubyracer-heroku', '0.8.1.pre3'
gem "pg"
end
This also failed to solve the issue
I have postresql installed on my system.
So what hell is the problem?

The key thing here is that the pg gem is required to run against the Postgres database that you end up using when you deploy to heroku (http://devcenter.heroku.com/articles/database)
Ideally, you want to be running Postgres locally so that you're not seeing any differences between development and production from a database standpoint.
If you want to stick with things how you have them simply adding gem "pg" to your Gemfile should fix this.
Once added, run:
bundle install
git add .
git commit -am "Added PG to Gemfile"
git push heroku master
heroku rake db:migrate

Please following steps for deploy on heroku server
First please remove the gem ='sqlite3' from Gemfile and add gem = 'pg'
Run this command on Project path: bundle install
git add .
git commit -am "add pg on gem file"
git push heroku master

Related

The git source is not yet checked out when running Docker

I'm currently facing an error when trying to use a gem from GitHub. I have the following in my Gemfile:
# Gemfile
source 'https://rubygems.org'
ruby '2.3.1'
gem 'sinatra'
gem 'rack'
gem 'puma'
group :development do
gem 'byebug'
gem 'rack-test'
gem 'rerun', github: 'alexch/rerun', branch: 'master'
end
When I run bundle install from Dockerfile it works with a message like:
...
Installing sinatra 1.4.6
Installing listen 3.1.5 (was 3.0.6)
Using rerun 0.11.0 from git://github.com/alexch/rerun.git (at master#3e4c486)
Bundle complete! 6 Gemfile dependencies, 14 gems now installed.
...
However, when I go to start the container I get:
The git source git://github.com/alexch/rerun.git is not yet checked out. Please run `bundle install` before trying to start your application
I've seen similar issues but not related to Docker.
Turns out I was able to find the issue. The problem was related to my Gemfile being used to build the Docker image.
I had not locally run a bundle install command which led to the Gemfile.lock not being updated. Once I ran the command the following was added to my Gemfile.lock:
## -1,14 +1,20 ##
+GIT
+ remote: git://github.com/alexch/rerun.git
+ revision: 3e4c486304be406cb86180ef70ec24e9ae055ce4
+ branch: master
+ specs:
+ rerun (0.11.0)
+ listen (~> 3.0)
Turns out that was all I needed. Once I had the updated file, rebuilt the image and ran the container everything worked as expected with bundle exec rerun. So the catch was that I was using the Gemfile.lock to help with caching / version locking but failed to keep it updated with my Gemfile.
In case anyone is interested there's an alternative.
During image creation, if your dockerfile runs bundle install it will generate a Gemfile.lock in the container. You can use docker run to get the contents, e.g.
docker run web cat Gemfile.lock
You can copy the contents and save a Gemfile.lock to your project directory.
Worked to me:
docker-compose run web bundle install

Error when deploying to Heroku via github

I've been trying to deploy my first Ruby on Rails application to Heroku to test it out and I receive the following error when using the manual deploy option. Just for some background notes I created the rails application using the operating system 'Windows 10', Ruby version 2.1.8p440 & Rails 4.2.5.1. If anymore information I will be happy to provide, thank you. I also have 'coffee-script-source' installed as a gem and its to make the project run correctly.
----- HEROKU MANUAL DEPLOY LOG START -----
An error occurred while installing sqlite3 (1.3.11), and Bundler cannot
continue.
Make sure that `gem install sqlite3 -v '1.3.11'` succeeds before bundling.
!
! Failed to install gems via Bundler.
!
! Detected sqlite3 gem which is not supported on Heroku.
! https://devcenter.heroku.com/articles/sqlite3
!
! Push rejected, failed to compile Ruby app
----- HEROKU MANUEL DEPLOY LOG END -----
Move your sqlite3 gem under development group
group :development, :test do
gem 'sqlite3'
end
Add pg gem under production group
group :production do
gem 'pg'
end
run bundle and try to push code to Heroku.

windows heroku run rake db:migrate error "/usr/bin/env: ruby.exe: No such file or directory"

I'm pretty new to Rails here and I've followed Ruby on Rails Tutorial for most of it. I have since decided to make my own application, but using the Rails 4 gem in beta. I have installed PostgreSQL on my local machine (Windows 7) and done development. Everything works great! (I love Rails much more than C#, ASP, .NET work that I do for a living!)
However, once I decided to push to Heroku, I've been pulling my hair out. Prior to pushing to Heroku, I did the standard:
c:\Sites\elms>git add .
c:\Sites\elms>git commit -m "My comment"
c:\Sites\elms>git push
c:\Sites\elms>git push heroku master
I've downloaded and installed the Heroku Toolbelt (not heroku gem.) The first error told me I needed to make sure that my Gemfile specified Ruby >= 1.9.3, so I added "ruby 1.9.3" to the top of my Gemfile:
source 'https://rubygems.org'
ruby "1.9.3"
gem 'rails', '4.0.0.beta1'
gem 'pg'
gem 'haml-rails'
gem 'httparty'
gem 'devise', git: 'git://github.com/plataformatec/devise.git', branch: 'rails4'
gem 'cancan'
gem 'bootstrap-sass'
gem 'formtastic'
gem 'formtastic-plus-bootstrap'
group :development do
gem 'annotate'
gem 'better_errors'
gem 'binding_of_caller'
gem 'guard-spork'
gem 'guard-rspec'
gem 'meta_request'
gem 'rb-notifu'
gem 'schema_to_scaffold'
gem 'wdm', :platforms => [:mswin, :mingw], :require => false
gem 'win32console'
end
group :development, :test do
gem 'rspec-rails'
gem 'pry'
gem 'spork-rails', git: 'git://github.com/sahilm/spork-rails.git', branch: 'rails-4'
gem 'spork', '~> 1.0.0rc3'
end
group :test do
gem 'capybara'
gem 'factory_girl_rails'
gem "shoulda-matchers"
end
group :assets do
gem 'sass-rails', '~> 4.0.0.beta1'
gem 'coffee-rails', '~> 4.0.0.beta1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.0.1'
The push finally worked without any issues, but when I tried to migrate the database, I got the following:
c:\Sites\elms>heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.2205
/usr/bin/env: ruby.exe: No such file or directory
I have also tried: heroku run bin/rake db:migrate, and it gives same error. I am using Getting Started with Rails 4.x on Heroku to push my Rails 4 app to Heroku. Any help would be greatly appreciated!
Oh, I also had an issue after running:
c:\Sites\elmx>gem install rails --pre
I solved this by adding C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\bin; to my environment Path variable in Windows 7 (it was giving me an error that it couldn't find rails when trying to execute anything such as:
rails -v
rails g controller User
But if I typed just:
rails
It would give me all of the commands I could use (as if running rails -h)
I set up my machine by using the Windows Rails Installer, then installing the Rails 4 gem. This is extremely frustrating and I've scoured the internet trying to find someone with the same problem.
EDIT 1:
I just deleted my user Path environment variable and modified my system Path environment variable to look like such:
C:\RailsInstaller\Ruby1.9.3\bin;C:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\bin;C:\Program Files (x86)\git\cmd;C:\Program Files (x86)\Heroku\bin
Updated my path variable to the above and uninstalled Heroku Toolbelt, then re-installed it (hence why the Heroku piece is in the path variable) and tried the following:
c:\Sites\elms>ruby -v
ruby 1.9.3p125 (2012-02-16) [i386-mingw32]
c:\Sites\elms>rails -v
Rails 4.0.0.beta1
c:\Sites\elms>heroku -v
! `-v` is not a heroku command.
! Perhaps you meant `-h`.
! See `heroku help` for a list of available commands.
c:\Sites\elms>heroku run rake db:migrate
Running `rake db:migrate` attached to terminal... up, run.2100
/usr/bin/env: ruby.exe: No such file or directory
c:\Sites\elms>heroku run bin/rake db:migrate
Running `bin/rake db:migrate` attached to terminal... up, run.2872
/usr/bin/env: ruby.exe: No such file or directory
EDIT 2:
So I got a little further in this venture. I found out that I could execute:
c:\Sites\elms>heroku run bash
~ $ cd bin
~/bin $ ruby rake db:migrate
And that would then run rake and migrate my database on Heroku. But the problem gets worse! I try to navigate to the page and it tells me that there is something wrong, so I run the log file and this is what I get:
c:\Sites\elms>heroku logs
2013-03-16T05:34:20+00:00 heroku[api]: Enable Logplex by
2013-03-16T05:34:20+00:00 heroku[api]: Release v2 created by
2013-03-16T05:34:36+00:00 heroku[slugc]: Slug compilation started
2013-03-16T05:35:37+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 13423 -e $RAILS_ENV`
2013-03-16T05:35:37+00:00 heroku[slugc]: Slug compilation finished
2013-03-16T05:35:37+00:00 app[web.1]: bash: bin/rails: No such file or directory
2013-03-16T05:35:39+00:00 heroku[web.1]: Process exited with status 127
2013-03-16T05:35:39+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 33539 -e $RAILS_ENV`
2013-03-16T05:35:40+00:00 app[web.1]: /usr/bin/env: ruby.exe: No such file or directory
2013-03-16T05:35:41+00:00 heroku[web.1]: Process exited with status 127
2013-03-16T05:35:41+00:00 heroku[web.1]: State changed from starting to crashed
2013-03-16T05:35:41+00:00 heroku[web.1]: State changed from crashed to starting
2013-03-16T05:35:44+00:00 heroku[web.1]: Starting process with command `bin/rails server -p 23452 -e $RAILS_ENV`
2013-03-16T05:35:44+00:00 app[web.1]: /usr/bin/env: ruby.exe: No such file or directory
This is getting really frustrating. I have no clue what the heck /usr/bin/env is. The only thing I can guess is that it's like PATH for Windows. If this is the case, why does the server not know where ruby.exe is?
I did make a non Rails 4 application and was able to post it to Heroku and view it with no issues. This is really getting on my nerves.
You need to change in your application first line of the 3 files:
bin/bundle
bin/rails
bin/rake
Instead
#!/usr/bin/env ruby.exe
must be
#!/usr/bin/env ruby
That's why is error:
/usr/bin/env: ruby.exe: No such file or directory
Then you do successfully:
heroku run rake db:migrate
It's work for me.
I had a similar issue and as others have already stated, changing the below helped.
#!/usr/bin/env ruby.exe to #!/usr/bin/env ruby
However, I also needed to remove some hidden carriage returns which were still present from developing on Windows originally (I guess?).
I used dos2unix to do this.
dos2unix bin/bundle bin/rake bin/rails
After that, I committed my changes, pushed to heroku and all was good.
I had this same problem, changed ruby.exe to ruby in the three files as described above, executed the
git push heroku master
step, which told me everything was up to date. Trying the
heroku run rake db:migrate
step again, it still didn't work; I got the same error about no such file or directory for ruby.exe. I examined my gemfile.lock as directed, but didn't see anything that looked windows-y.
I then executed these:
git add .
git commit -m "My comment"
and tried again with
git push heroku master
This time, boatloads of messages went by, including:
Removing Gemfile.lock because it was generated on Windows.
so perhaps there was something wrong with it and I just didn't know what I should be looking for in it.
Trying again to
heroku run rake db:migrate
looks to have worked, as I got
Running rake db:migrate attached to terminal... up, run.3260
== CreateUsers: migrating ====================================================
-- create_table(:users)
-> 0.0409s
== CreateUsers: migrated (0.0412s) ===========================================
My best guess is that the change to remove the .exe from bundle, rake, and rails did not actually get pushed up on the first try of
git push heroku master
and the
git add .
and
git commit -m "My comment"
were necessary to make it get pushed up. This is my first attempt at anything with git/heroku/ruby, so I don't know enough to say why the other two commands were required, but leave my experience documented here in case it helps anybody else.
Thanks so much for the clue above that it was the .exe in those three files that caused the problem.
bin/bundle
bin/rails
bin/rake
Instead
#!/usr/bin/env ruby.exe
must be
#!/usr/bin/env ruby
(thanks to previous post)
make sure there are no references to windows in the gemfile.lock - they can just be deleted
then
git push heroku master
if there are still problems use
heroku logs (copying text to a text editor makes it easier to cut and paste for solutions)
Try this:
sudo apt-get install build-essential patch ruby-dev zlib1g-dev liblzma-dev
and then install Nokogiri:
gem install nokogiri

Why my ruby application works locally and does not run on Heroku?

I have a Ruby 1.8.7 application that works correctly locally. To load it on Heroku, I changed the database from SQLite to PostgreSQL, install PostgreSQL 9.1.3, I changed the Gemfile replacing gem sqlite3 with:
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
And changing the part production of config/database.yml with:
production:
adapter: postgresql
database: project_production
pool: 5
timeout: 5000
Then I run bundle install --without production successfully. Next I created a git repository with:
git init
git add *
git commit -m "text"
Later I create a heroku application with heroku create --stack bamboo-ree-1.8.7 , git push heroku master and heroku rake db:migrate successfully.
But it didn't work!
What's missing? I've done something wrong or I have not made ​​any statement?
Is "git add *" working ? I think you'd better use :
$ git add .
As Larsenal asked, could you post your logs ?
$ heroku logs
The basic information about heroku deployment is here.
You don't need the "production" block in database.yml, this is automatically generated by heroku when deploying.
Kind regards,
Max

Sinatra + Heroku + Datamapper deploy issues with dm-sqlite-adapter

For some reason, heroku tries to require dm-sqlite-adapter, even though it should use Postgres here. Note, that this happens when I open any URL - not during the git push itself.
I built a default facebook app.
The Gemfile:
source :gemcutter
gem "foreman"
gem "sinatra"
gem "mogli"
gem "json"
gem "httparty"
gem "thin"
gem "data_mapper"
gem "heroku"
group :production do
gem "pg"
gem "dm-postgres-adapter"
end
group :development, :test do
gem "sqlite3"
gem "dm-sqlite-adapter"
end
Datamapper setup:
# Setting up the database
DataMapper.setup(:default, ENV['DATABASE_URL'] || "sqlite3://#{Dir.pwd}/data/mydatabase.db")
Relevant log fragment, when any URL is opened:
Starting process with command `bundle exec thin -R config.ru start -p 34984`
2012-01-18T15:11:55+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/adapters.rb:163:in `require': no such file to load -- dm-sqlite-adapter (LoadError)
2012-01-18T15:11:55+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/dm-core-1.2.0/lib/dm-core/adapters.rb:163:in `load_adapter'
Tried related solutions, but with no help so far.
BTW: bundle install says Using do_postgres and Using dm-postgres-adapter. Am I missing something about Datamapper setup?
Well, too many Rails apps on Heroku, I took the shared db presence for granted. heroku config showed neither DATABASE_URL or SHARED_DATABASE_URL set.
Issuing heroku addons:add shared-database:5mb solved the problem.
Strange, that the db wasn't automatically added, despite having 'pg' gem in Gemfile.
Quote from http://devcenter.heroku.com/articles/cedar:
A Heroku shared PostgreSQL database (shared-database:5mb) will be
automatically added to your app in any of the following cases:
The app is a Rails application
The pg gem is specified in the Gemfile
Try doing DataMapper.setup(:default, ENV['DATABASE_URL'] || 'postgres://user:password#hostname/data/mydatabase.db') instead. Heroku is probably looking at the protocol, and therefore requiring SQLite’s dependencies.

Resources