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
Related
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.
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.
I am trying to get a simple tutorial app up and running with Rails, but have run into this problem almost right away. I create the new ruby app, cd to the directory and run rake db:create. I get the following
Please install the sqlite3 adapter: 'gem install activerecord-sqlite3-adapter' (sqlite3 is not part of the bundle. Add it to the Gemfile.)
But I do have the gem added to the Gemfile, like so:
gem 'sqlite3'
Also, when I tried to gem install the adapter, I was given an output saying that it did not exist in any repository. This is my first time using rails, any ideas on how to fix this?
*Edit
gem install activerecord-sqlite3-adapter produces the following:
Error: Could not find a valid gem 'activerecord-sqlite3-adapter' in any repository.
The it offers some alternatives, only one of them being sqlite3. It is called activerecord-jdbcsqlite3-adapter. Is this the one I need possibly?
Thank you for everyone's input. I never was able to resolve this issue, and ended up just using the Rails Installer instead. So much easier, just make sure you delete all your previous versions of Rails, Ruby, Gems, everything. Then use the installer.
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.
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