rails connect to database - ruby-on-rails

I'm trying to open by my rails console in my newsly created app, but I can't connect to a database. It looks like there might be a problem with sqlite3-1.3.3 vs 1.3.4
$ rails c
/Library/Ruby/Gems/1.8/gems/activerecord-3.1.1/lib/active_record/connection_adapters/abstract/connection_specification.rb:71:in `establish_connection': Please install the sqlite3 adapter: `gem install activerecord-sqlite3-adapter` (can't activate sqlite3 (~> 1.3.4, runtime), already activated sqlite3-1.3.3. Make sure all dependencies are added to Gemfile.) (RuntimeError)
Install
$sudo gem install
ERROR: could not find gem activerecord-sqlite3-adapter locally or in a repository
What gems I have installed
$gem list
*** LOCAL GEMS ***
...
sqlite3 (1.3.3)
sqlite3-ruby (1.3.3, 1.3.2, 1.2.5)
I'm using rails 3.1.1
EDIT:
Here is my gemfile
source 'http://rubygems.org'
gem 'rails', '3.1.1'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'sqlite3'
gem 'json'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.1.4'
gem 'coffee-rails', '~> 3.1.1'
gem 'uglifier', '>= 1.0.3'
end
gem 'jquery-rails'
Running bundle install produces this
$sudo bundle install
using rake (0.9.2.2)
...
Using sqlite3 (1.3.3)
Your bundle is complete! Use bundle show [gemname] to see where a bundled gem is installed.
$ bundle show sqlite3
/Library/Ruby/Gems/1.8/gems/sqlite3-1.3.3

You're using Rails 3.1, which uses bundler to manage gems.
Add gem 'sqlite3' to your Gemfile
run bundle form the command line
This will install the gems your app needs. You should then be able to launch the console.

I've seen similar situations in the past because of missing/bad shared libraries. Gems install ruby code, native bindings to libraries, but they do not install the external libraries themselves.
The dependency for sqlite on Ubuntu, for example, is libsqlite3-dev.
$ sudo apt-get install libsqlite3-dev
For OSX:
Install sqlite3 on mac osx?

Related

'bundle install' keeps installing gem sqlite3 version 1.4.2 even if not in Gemfile

I need sqlite3 v1.3.9 gem installed for my app, so I add this line to the Gemfile:
gem 'sqlite3', '= 1.3.9'
However, when I run 'bundle install', it installs v1.4.2 of that gem.
I modified the above line to
gem 'sqlite3', '= 1.3.9', '< 1.4'
No joy -- sqlite v1.4.2 is installed (even if I remove any reference to 'sqlite3' from the Gemfile completely).
My Gemfile was created when I used rails new appname, so it is not fancy at all... I only added gem devise to it.
Gemfile.lock doesn't contain any reference to sqlite3. I removed it anyway and it didn't help.
As another option, I installed v1.3.9 via gem install sqlite3 -v 1.3.9 and I removed v1.4.2 with
# bundle exec gem uninstal sqlite3
Select gem to uninstall:
1. sqlite3-1.3.9
2. sqlite3-1.4.2
3. All versions
> 2
Successfully uninstalled sqlite3-1.4.2
...but as soon as I tried to add v1.3.9, I got:
# bundle add sqlite3 -v 1.3.9
[!] There was an error parsing `injected gems`: You cannot specify the same gem twice with different version requirements.
You specified: sqlite3 (~> 1.4) and sqlite3 (= 1.3.9). Bundler cannot continue.
# from injected gems:1
# -------------------------------------------
> gem "sqlite3", "= 1.3.9"
# -------------------------------------------
I'd grateful for any hints on why v1.4.2 keeps being installed and, most importantly, how do get the bundler forget about v1.4.2 and accept v1.3.9?
Thanks a lot!
There might be some gem in your app that requires sqlite3-1.4.2 and that is causing an issue with installing sqlite3-1.3.9. You should check your Gemfile.lock and look for any gem that is adding sqlite3-1.4.2 as a dependency.
There should be a gem in your app that requires sqlite3-1.4.2 and that is causing an issue with installing sqlite3-1.3.9. You should check your Gemfile.lock and look for any gem that is adding sqlite3-1.4.2 as a dependency.

Ruby On Rails: therubyracer x86-mingw32 missing gems

when I tried to start Server with command rails -s that throw an error:
Could not find gem 'therubyracer x86-mingw32' in any of the gem sources listed i
n your Gemfile.
Run bundle install to install missing gems.
I also try with
gem install
gem update ...
but no effect
my gem file:
gem 'therubyracer', group: :production
I don't know why that can not run! but run with another project is OK.
how can I resolve this?
You can run bundle install --without production to skip that gem being installed for development.

Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)

In my Gemfile I have: mysql2 (0.4.4)
I got this error when launching my Rails server: Specified 'mysql2' for database adapter, but the gem is not loaded. Add gem 'mysql2' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
I read and searched some threads on this website. The recommendations were to downgrade mysql2
"version 0.3.18 of mysql2 by adding this line to your gemfile:
gem 'mysql2', '~> 0.3.20'"
When I did this I tried to rerun bundle install and I got this error.
[!] There was an error parsing Gemfile: unterminated string meets end of file. Bundler cannot continue.
# from /Users/john-michaelnalettenalette/simple_cms/Gemfile:7
# -------------------------------------------
# # Use mysql as the database for Active Record
gem ‘mysql2’, `~> 0.3.20’
# # Use SCSS for stylesheets
# -------------------------------------------
Any Ideas would be appreciated.
You started a string which you didn't end at the end of this line :
gem 'mysql2', '~> 0.3.20'"
Change it to this:
gem 'mysql2', '~> 0.3.20'
I had the same error on rails v 4.2.10. Ubuntu 18:10
Installing mysql2 0.3.21 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
the solution suggested in the error message was:
libmysqlclient is missing. You may need to 'apt-get install libmysqlclient-dev'
or 'yum install mysql-devel', and try again.
this worked!
note: I am bundling an old app which depended on mysql, which is not yet installed on my machine. installing mysql may also have solved my issue.

Rails: gem file/ bundle install with gem 'bootstrap-sass'

I added the line to the gem file:
gem 'bootstrap-sass' '3.3.2.0'
then I got:
$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching additional metadata from https://rubygems.org/..
Resolving dependencies...
Could not find gem 'bootstrap-sass3.3.2.0 (>= 0) ruby' in the gems available on this machine.
so I downloaded and installed it from rubygems.org:
$ gem install bootstrap-sass -v 3.3.2.0
Fetching: autoprefixer-rails-5.1.11.gem (100%)
Successfully installed autoprefixer-rails-5.1.11
Fetching: bootstrap-sass-3.3.2.0.gem (100%)
Successfully installed bootstrap-sass-3.3.2.0
2 gems installed
Then tried:
$bundle install
or/and
$bundle update
And still getting the message:
Could not find gem 'bootstrap-sass3.3.2.0 (>= 0) ruby' in the gems available on this machine.
What should I do?
You forgot the comma between gem name, and version.
gem 'bootstrap-sass', '3.3.2.0'
Refer to the documentation, you need to specify your optional parameters separated by ,.
If you are installing any gem with perticular version you should have to give a comma in between gem and version (or any other parameter its optional).
like,
gem 'bootstrap-sass','3.3.2.0'
but if you want to install only gem without any version you need to give only gem file name,that enough
like,
gem 'bootstrap-sass'
The benefit of above declaring gem is that it's version independent,because bundle installer will automatically download latest version gem, for our project.
In the below code you can see that i used Rails with 4.2.1 version and i separated with it comma, but for further gems I did not mentioned any version.
so bundle installer will automatically install latest version for you are Rails project.
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.2.1'
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'

Nokogiri gem installation error with spree

I'm getting this error when I try to bundle install
Bundler::GemspecError: Could not read gem at /home/theareba/.rvm/gems/ruby-2.0.0-p353/cache/nokogiri-1.6.1.gem. It may be corrupted.
An error occurred while installing nokogiri (1.6.1), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.6.1'` succeeds before bundling.
I've tried removing nokogiri in the cache and bundle installing again in vain.
Here's my gemfile
source 'https://rubygems.org'
gem 'rails', '4.0.0'
ruby "2.0.0"
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-1-stable'
gem 'spree', github: 'spree/spree', branch: '2-1-stable'
gem 'bootstrap-sass', '2.3.2.0'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder'
group :development, :test do
gem 'turn', :require => false
gem 'sqlite3'
gem 'taps', :require => false
gem 'rspec-rails'
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor'
end
UPDATE
Error that occurs when I run gem install nokogiri -v '1.6.0'
Fetching: mini_portile-0.5.2.gem (100%)
Fetching: nokogiri-1.6.0.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:5:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/nokogiri-1.6.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/nokogiri-1.6.0/ext/nokogiri/gem_make.out
Note: I've installed both libxslt1-dev and libxml2-dev that are requirements in nokogiri installation.
I've also tried gem install nokogiri -v '1.6.1' but it still fails. I've installed nokogiri -v 1.5.0 in another app so I tried it in this app and got the error that spree requires nokogiri version 1.6.0 or greater. I'm I missing something?
So here's what solved my problem. I created a new gemset i.e
rvm gemset create nokogiri
rvm use ruby-2.0.0-p353#nokogiri
Note: I'm using rvm and ruby 2.0.0. Then I made sure I've got necessary lib installed by running
sudo apt-get install libxml2-dev libxslt-dev
The libraries happened to be already installed. Then I installed nokogiri
gem install nokogiri -v '1.6.1'
It installed successfully. And finally ran bundle install to get all my gems. Hope this helps anyone having the same issue.
Check the RVM gemset. I fixed it by restoring the gemset. If you try upgrading to 4.0.2? I used Nokogiri 1.6.1 with Ruby 2.0.0 and Rails 4.0.2
try this
sudo apt-get install ruby-dev
sudo apt-get install libxml2 libxml2-dev libxslt1-dev
and reinstall nokogiri
sudo gem install nokogiri

Resources