How can I use SQLite 3 with RubyOnRails? - ruby-on-rails

First, I'm bad at english, so I can't give a lot of details.. I've been trying to create a website using ruby on rails:
rails new azer
rails generate controller pages home
The last command doesn't work and there's an error occuring during generating:
/home/esteban/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activerecord-4.2.10/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)
So I opened my gemfile:
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.10'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
...
...
I'm unsure what might be the error cause thus I don't know how to proceed.
Versions:
Ruby 2.4.4
Rails 4.2.10
SQLite3 1.4.1.
EDIT : Thanks for your help everyone, I appreciate it ! I just tried to reinstall rails and it worked

It seems version 1.4.x won't work with Rails 4. Install version 1.3.13 instead:
Unisntall version 1.4.1:
gem uninstall sqlite3 -v1.4.1
Modify Gemfile:
gem 'sqlite3', '~> 1.3.13'
And run bundle install.

Related

What is the easy way to upgrade rails application?

I am working on a very old rails project. The gemfile is like this:
source 'http://rubygems.org'
gem 'rails', '2.3.17'
gem 'rake', '0.8.7'
gem 'rdoc', '3.6.1'
gem 'mysql', '2.8.1'
gem 'roo', '1.9.7'
gem 'rubyzip', '0.9.4'
gem 'pdf-writer', '1.1.8'
gem 'prawn', '0.12.0'
gem 'sendmail'
gem 'htmldoc', '0.2.3'
The ruby version is 1.8.7
What is the easy way to upgrade this rails app ? Can I just change the version of each gem to the latest one and expect it will work fine?
There is no easy way. Before You start upgrade you must add tests to be sure that application will still work after upgrade.
Then I recommend to change gem description to following syntax:
gem 'mysql', '~> 2.8.1' it tells bundler to update only last number of version of gem.
Then repeat following step
change rails version to next
bundle update rails
corrected conflicted gem version by hands
bundle update

Phusion error: undefined method `has?' for Sass::Util:Module

I get the following error issued by Phusion when loading a web page:
There was an error while trying to load the gem 'compass-rails'.
Gem Load Error is: undefined method `has?' for Sass::Util:Module
Did you mean? hash
Hash
Backtrace for gem load error is:
/Volumes/Data/htdocs/zetcho/vendor/bundle/gems/compass-0.12.2/lib/compass/sass_extensions/functions/urls.rb:5:in `has?'
The code at the indicated location is:
module Compass::SassExtensions::Functions::Urls
def self.has?(base, instance_method)
Sass::Util.has?(:instance_method, base, instance_method)
end
My gem file contains:
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.1.2'
# Use mysql as the database for Active Record
gem 'mysql2', '~> 0.3.18'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 5.0'
# Use Compass for stylesheets
gem 'compass-rails'
# Use the Compass extension susy
gem "sprockets"
gem 'susy'
I've just created the Ruby on Rails site using Rails 5.1.2 and ruby 2.3.1. I have a much older site that works fine with the gem. Did I miss a step in the overall install or is this a bug with compass-rails?
I got the same error when I tried to add a controller:
rails generate controller home index
After more digging around, I found a similar problem. I fixed this one by changing the gem file to:
gem 'compass-rails', github: 'Compass/compass-rails'
Then:
rm gemfile.lock
bundle
It seems that the issue can be found in compass-rails 2.0.0. The version 3.0.2 seems to fix this issues. So a possible solution is :
# Gemfile
gem 'compass-rails', '~> 3.0.2'
Then bundle update compass-rails
This avoids targeting the compass-rails git master branch in favor of an actual release.
I came here having the same issue with a grunt compiling issue trying to use Compass/Sass, if this might help someone, my issue was caused because I had an updated version of Sass (sass-3.7.4) that was higher that the max-version compatible with compass, I uninstalled sass:
gem uninstall sass
Which in turn uninstalled compass, and reinstalled compass letting it choose the right version, and problem solved.
gem install compass

"postgresql gem is not loaded" error deploying a Ruby on Rails application on Heroku

I am trying to use postgresql with Ruby on Rails on Heroku but got an error
Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError)
Please help me to solve this issue.
This worked for me
gem 'pg', '~> 0.20'
Thanks to Piers C
Got this answer from
Heroku and Rails: Gem Load Error with Postgres, however it is Specified in GEMFILE
In your Gemfile
group :production do
gem 'pg'
end
Then run bundle install and try to deploy on Heroku.
If you want to use PostgreSQL on all environments and not only in production (recommended) add the gem outside the :production group and remove other database adapters such as sqlite.
As a side note, you may also want to add the rails_12factor gem as suggested by Heroku.
Add pg in gemfile
gem 'pg', '~> 0.20'
then bundle update & commit Gemfile & Gemfile.lock to heroku.
simple include like gem 'pg' will not work.
I added the following version into my gemfile, and it is solved.
gem "pg", "~> 0.18"

The bundle currently has rails locked at 3.2.12. whats to do?

I've changed in my gemfile the rails version from 3.2.12 to 4.2.0
then I got this error:
The bundle currently has rails locked at 3.2.12
so I tried bundle update / and bundle update rails ... but I got this:
Bundler could not find compatible versions for gem "rails":
In Gemfile:
prototype-rails (>= 0) ruby depends on
rails (~> 3.2) ruby
rails (4.2.0)
What do I have to do?
Update Gemfile:
source 'http://rubygems.org'
#gem 'rails', '3.2.12'
gem 'rails', '4.2.0'
gem "airbrake"
#gem "mysql"
gem 'mysql2', '~>0.3.7'
gem 'fastercsv'
gem 'newrelic_rpm', :group => [:production, :staging]
gem "xml-simple", :require => "xmlsimple"
gem "will_paginate", "~> 3.0.0"
gem "json", '1.7.7'
gem "default_value_for"
gem "whenever"
gem 'charlock_holmes'
gem 'prototype-rails'
gem 'rails_autolink'
group :development do
gem 'capistrano'
gem 'capistrano-ext'
end
Just run
bundle update
without telling to update just a specific gem (like rails). This allows bundler to find the lastest possible combination for all gems in the Gemfile.
The prototype-rails gem is not actively supported anymore. You should try to replace it as soon as possible (even if the latest version still works for you).
Furthermore: Multiple configuration settings have changed between Rails 3.2 and 4.2, you will have to change some of your config and core files. You also might want to read the Rails Guide: Upgrading Rails.
I suggest to upgrade your app in smaller steps (3.2 -> 4.0, 4.0 -> 4.1, 4.1 -> 4.2). Make sure that the app works in each step before you continue to the next. Also, watch out for deprecation warnings in the console or the logs.
remove your gemfile.lock
rm Gemfile.lock
then add
rails 4.2.0 in your Gemfile
then
bundle install
I think, the problem is in prototype-rails
https://github.com/rails/prototype-rails
Below Comment of prototype-rails gem
Unfortunately, due to limited manpower and resources, the Rails core team has not been able to confirm if this gem currently works with Rails 4.1 and above. If you have found any problems while upgrading your application, please report them at the issue tracker, or better yet, submit patches by sending a pull request.
Tried to remove first remove prototype-rails then run
bundle update

Rails has disappeared

I developed a web in rails and it was working perfectly for months. Now I went to my web folder and started "rails server" but got the reply:
Rails is not currently installed on this system. To get the latest version, simply type:
$ sudo gem install rails
I really don't understand how rails could disappeared from my system, I am sure I haven't removed it. I was using rails 3.1 on a Mac. Any clues or suggestions?
Gemfile:
source 'rubygems.org';
gem 'rails', '3.1.0.rc5'
# gem 'rails', :git => 'git://github.com/rails/rails.git'
#group :test, :production do
# gem 'mysql', '5.1.58'
#end
#group :development do gem 'sqlite3'
#end
#gem install activerecord-mysql-adapter
gem 'json'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', "~> 3.1.0.rc"
gem 'coffee-rails', "~> 3.1.0.rc"
gem 'uglifier'
end
gem 'jquery-rails'
I have faced a similar problem.
I believe rails 3.1.0 is buggy, i myself tried my hands on it and reverted back to the stable version of rails i.e. anything but 3.1.0. It would have been better if you have installed RVM. With RVM you can have one or more rails version, in fact an entire gemset.
I myself have a global gemset and another gemset named rails1.
rvm gemset create gemset_name
Once you install the like of ruby and rails version you can set it default
rvm gemset default#gemset_name
I did this back then and it works fine on my end. More on RVM
Hope it helps.

Resources