Using Datamapper for Heroku without installing Postgres locally - ruby-on-rails

I want to use datamapper in a rails app i want to deploy on heroku. Therefore i need to add dm-postgres-adapter to my Gemfile. Is there any way to have heroku installing this gem without installing postgreSQL locally?

Limit its context to production using "group".
group :production do
gem "gemname"
end

Related

Rails app on Heroku

I'm working on ruby on rails project on hosting machine "nitrous"
I'm trying to push my files on Heroku using command
git push Heroku master</code>
and this is the building log:
note: building log is really big mess all what you need is to read site
Docs to know what they really support before trying to install
something
Heroku does not support sqlite3. It instead uses a PostgreSQL database. I'd recommend following these docs for deploying Rails apps to Heroku:
Rails 4: https://devcenter.heroku.com/articles/getting-started-with-rails4
Rails 5: https://devcenter.heroku.com/articles/getting-started-with-rails5
It's as easy as going to your Gemfile and changing gem 'sqlite3' to gem 'pg'. Be sure to run bundle afterwards.
You'll then need to set up a simple database.yml file, and then rebuild your schema for local development.
Follow the docs and you'll be fine.
in youe gemfile
gem 'pg'
group :development do
gem 'sqlite3'
end
then
bundle install
push Gemfile and Gemfile.lock to git.

ActiveRecord::ConnectionNotEstablished error with ruby on rails

I was trying to learn ruby on rails, so I installed the gem version 4.0.0, when I start my server, and go to localhost:8000, it brings me an error page with error message:
ActiveRecord::ConnectionNotEstablished.
I'm using sqlite3, not MySQL. Any help is appreciated.
edit: i fixed it, had to do with my database.yml
Make sure that you have installed sqlite3 gem: gem install sqlite3 or run bundle install if you have the gem listed on your Gemfile (which you should).
After that run the following commands:
rake db:create # creates the database
rake db:migrate # creates the tables based on your migration files
If the above two works fine, your application should be able to connect to the database. If not you probably have a configuration problem on your config/database.yml.

trouble generating new rails controller

I am new to ruby on rails development. I am currently having difficulties generating a new rails controller. here is what I input into the terminal:
$ rails generate controller static_pages home help
here is the response I receive:
/usr/local/rvm/gems/ruby-2.3.0/gems/activerecord-4.2.5/lib/active_record/connection_adapters/connection_specification.rb:177
:in `rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded.
Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
I am also using Heroku for production so I initially removed sqlite3 because Heroku cant use it by doing:
$ gem uninstall sqlite3
and I removed it from my gemfile and gemfile.lock. Was this a mistake? Any guidance would be much appreciated.
The error is because the config/database.yml file still has sqlite3 as the database adapter for the development database.
If you know which database you want to use for your local development database, set the appropriate database adapter in this file.
Heroku can't use sqlite3; however, you can use sqlite3 for your local development database, and specify postgres or mysql for production database.
Since you are a total beginner, I would recommend following the steps from a detailed tutorial as it is till you become familiar with the various concepts. Michael Hart's Rails Tutorial book is available for free online, and is a very good resource for beginner rails developers.
you cold try to rm Gemfile.lock and bundle install to reinstall your gems
Also make sure that the sqlite3 gem is in the development group
gem 'sqlite3', :group => :development
So that it will not be install on Heroku

My heroku app's generated files

I have a rails app that is deployed to Heroku, I don't know why, but I can't view the application on localhost nor can I access the files created by heroku run rails generate []. The gem in this situation is activeadmin but I would like to know how to get the files that are generated from this command.
The error I get when running rails generate active_admin:install
/Users/michaelscaria/.rvm/gems/ruby-1.9.3-p385/gems/activerecord- 3.2.11/lib/active_record/connection_adapters/postgresql_adapter.rb:1208:in `initialize': FATAL: database "crowdery_development" does not exist (PG::Error)
You need to add gem 'pg' in your gemfile.
group :production do
gem "pg"
end
Before bundle install you need to install 'postgresql' using command
sudo apt-get install postgresql
After that do
bundle install --without production
Turns out that I didn't use the same database name that I was had created the app with.

Heroku gets error with Ruby Mongrel gem

Can't quite find the answer for my error in related posts.
I'm working my way through the on-line version of the Ruby on Rails Tutorial, Chapter 2
http://ruby.railstutorial.org/chapters/a-demo-app#top
and I'm near the bottom where I've created a small 2-table database and committed it to git. But it fails when I try to deploy with 'git push heroku master'. The same command worked previously before I added the tables to the app (and before I got Mongrel to work on the demo_app, I think).
My bundle includes Ruby 1.8.7, Mongrel 1.1.5 and sqlite3 1.3.3. I'm getting the line:
Installing mongrel (1.1.5) with native extensions /usr/ruby1.9.2/lib/ruby/1.9.1/rubygems/installer.rb:483:in 'rescue in block in build_extensions':ERROR: Failed to build gem native extension. (Gem:Installer::ExtensionBuildError).
How do I get around this problem? Can Heroku handle Mongrel at all? Or is it due to having a sqlite3 database? Why does the error mention Ruby1.9.2 when that's not in my bundle?
You don't need to use mongrel at all, and should simply remove it from your Gemfile. Whenever you see a reference to starting mongrel in your tutorial, just use ./script/server instead (or rails server if you're on Rails 3). It will run WebBrick, and that's good enough for development work.
If you really want to retain mongrel for local use you can group it as follows in Gemfile.
group :development do
gem "mongrel"
end
Note that you will likely still have to tell Heroku to not bundle your development gems or you'll run into the same error. If you're on the Cedar stack, then just get rid of the mongrel gem entirely.

Resources