'require': can not load such file -- sqlite3/sqlite3_native (LoadError) - ruby-on-rails

Getting this error while learning tutorial from this site.
http://ruby.railstutorial.org/chapters/a-demo-app#sec-demo_users_resource
tried to run this rails command on windows
rails generate scaffold User name:string email:string
and getting such error as:
> .../lib/sqlite3.rb:6:in 'require':cannot load such file -- sqlite3/sqlite3_native(LoadError)
>../lib/sqlite3.rb:2:in rescue in <top(required) >
>../bundler/runtime.rb:72:in 'require'
>.../bundler/runtime.rb:72:in block (2 level)
>from bin/rails:4: in 'require'
>from bin/rails:4: in <main>
I have already tried other answers like adding directory of sqlite to PATH..(its already there C:\RailsInstaller\Ruby2.0.0\lib\ruby\gems\2.0.0\gems\sqlite3-1.3.7-x86-mingw32)..
sqlite3(1.3.7-x86-mingw32 )is there in my gem list but still getting this error.
I have also tried to put sqlite3ext.h and sqlite3.h into /ext folder but its not working
tried this command
gem install sqlite3 --platform=ruby -- --with-sqlite3-dir=C:/path/to/sqlite3
no results
here is the Content of my database.yml
here is the database.yml file contents
# SQLite version 3.x
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
UPDATE:
As adviced by one the user which really help me " you'll run into several problems that will be frustrating purely because on Windows. If you can't remove Windows, download Virtual Box and use a Linux Distro on it. It will make life much easier for you." Switching to Linux resolved everything. thanks https://stackoverflow.com/users/1092260/althaf-hameez for this advice.

See https://stackoverflow.com/a/16748607/2466276.
My actions:
1. Download http://packages.openknapsack.org/sqlite/sqlite-3.7.15.2-x86-windows.tar.lzma
2. Unpack to C:\Knapsack\x86
3. gem uninstall sqlite3
4. gem install sqlite3 --platform=ruby -- --with-opt-dir=C:/Knapsack/x86

Related

Ruby on Rails - could not load postgres adapter

Building a rails app on heroku (locally). Following their tutorials for rails, and installing postgres locally.
When ever I run the server or generate a migration I get the following err:
LoadError (Could not load 'active_record/connection_adapters/posgtres_adapter'. Make sure that the adapter in config/database.yml is valid. If you use an adapter other than 'mysql', 'mysql2', 'postgresql' or 'sqlite3' add the necessary adapter gem to the Gemfile.):
database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
development:
<<: *default
database: myapp_development
username: Name
password: secret
host: localhost
Gem file has: gem 'rails' '4.2.0', and gem 'pg' installed
my machine's OS: Windows 64x
Any and all help appreciated.
Doubtful this is the same issue you are having but, posting these details in case it gives a lead. I'm using Windows 10
I had the same error message. To troubleshoot, I tried to do a reinstall of pg with 'gem install pg' but a file was locked.
Found I had a process still using one of the PG files and shut down the process, deleted the entire pg directory found at C:\Ruby200-x64\lib\ruby\gems\2.0.0\gems\pg-0.18.3-x64-mingw32
Reran 'gem install pg' rake db:setup, rake db:create, rake db:migrate and the error was gone.

Gem::LoadError: when trying to deploy on Heroku - Rails 4

I am trying to deploy an app (just a simple app from a Rails tutorial) to heroku but it keeps giving me the same error message. I use the command:
git push heroku master
It starts well, and then suddenly appears this error:
-----> Preparing app for Rails asset pipeline
Running: rake assets:precompile
rake aborted!
Gem::LoadError: Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile.
I did bundle install already, everything went smooth there.
Here is my Gemfile:
# Use sqlite3 as the database for Active Record
gem 'sqlite3'
Maybe something I am missing something on databse.yml file?
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
By the way, I don't know if it helps, but I am using Rails 4.0.4, Ruby 2.1.1 and the version of SQLite which comes already installed on Mac, which is 3.7.13
Kirti is right in saying that Heroku does not support sqlite as adapter,
do the following
in the Gemfile:
group :production, :staging do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
end
in database.yml
production:
adapter: postgresql
database: name_of_your_db
pool: 5
timeout: 5000
SQLite is not intended as a production grade database. Instead Heroku provides production grade PostgreSQL databases as a service.
Read the details SQLite on Heroku

capistrano error msg: Please install the pg adapter: `gem install activerecord-pg-adapter` (cannot load such file --

I am using capistrano and get this error message:
Please install the pg adapter: `gem install activerecord-pg-adapter` (cannot load such file -- active_record/connection_adapters/pg_adapter)
I have removed the gem 'pg' from my Gemfile and bundle installd . I don't see the pg gem in my Gemfile.lock. I have also changed my production db to a sqlite3 adapter. Why is Rails 3.2 / Capistrano / Bundler asking for this? I'm not using it and not in Gemfile.lock and how do I resolve it? I am using ubuntu 12.04 on server that this is happening on.
thx in advance
Also, when I run what it tells me to run, I get:
deploy#oahu:~$ gem install activerecord-pg-adapter
ERROR: Could not find a valid gem 'activerecord-pg-adapter' (>= 0) in any repository
^CERROR: Interrupted
deploy#oahu:~$ \
** edit 1 **
from root of app
Fri Mar 22$ grep -ri 'pg-adapter' *
Fri Mar 22$
database.yml
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
here's a screenshot of the database.yml file on github:
Check your database.yml. You probably have an entry in it called pg-adapter, when the correct adapter for Postgres is postgresql. If you remove or replace that, this should work.

Redeploying Rails app results in new bundling error with Passenger

I deployed my first rails app to a production server a few days ago. Since then, I've been working on some fixes on my development machine and I pushed those over to the production server via git. I touched the restart.txt file and then restarted Apache, and now I'm getting a Passenger error that I think is related to gems and bundle.
When I first started development I ran into an issue (here) and I removed the .bundle directory. I then ran bundle install again on my development machine, and all seemed well while I fixed some bugs.
Now I'm ready to redeploy the next version of the app, and after these errors, I checked and noticed that I don't even have a .bundle directory anymore. bundle install doesn't create a new one. I assume nothing's going to work without that? Should I just manually create the requisite files or is there a command to regenerate those?
EDIT to add error: syntax error on line 3, col 2: adapter:sqlite3'
database.yml:
# SQLite version 3.x
gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
Is the gem install sqlite3 in your listing of database.yml actually present in that file? If that is the case than that is the cause of the error as it is invalid YAML. Also, the statement doesn't make sense here, as the file isn't interpreted by neither bundler nor ruby.
At best, just remove (or comment) that statement there and try gain.
Edit: Generally, whitespace (especially leading whitespace) is rather important in YAML. Don't mix spaces and tabs here. It would confuse the parser. Also there need to be a space between the key and the value in a hash like so
key: value
# ^ this space is important!
Please refer to YAML's Wikipedia article for more info about YAML syntax.
#Paul, can you try updating your gemfile as follows
group :production do
# gem 'mysql2' # disabled to debug Paul's issue.
gem 'sqlite3-ruby', :require => 'sqlite3'
end
group :development do
gem 'sqlite3-ruby', :require => 'sqlite3'
end
Let me know how this pans out.

"no such file to load -- pg" when trying rake db:create

The symptom of my problem is pretty simple:
$ rake db:create
(in /home/jason/projects/blog)
rake aborted!
no such file to load -- pg
(See full trace by running task with --trace)
I've already successfully run bundle install and gem install pg, so I don't know what else I might need to do.
Here's my `config/database.yml if it helps:
# SQLite version 3.x
# gem install sqlite3-ruby (not necessary on OS X Leopard)
development:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password: foo
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
adapter: postgresql
encoding: unicode
database: blog_development
pool: 5
username: blog
password: foo
production:
adapter: sqlite3
database: db/production.sqlite3
pool: 5
timeout: 5000
I figured it out. If I use pg instead of postgresql in my config/database.yml, it works.
Go to console and type below:
vim Gemfile
Inside the file commend the below:
- #gem 'sqlite3-ruby', :require => 'sqlite3'
Inside the file add the below:
- gem 'pg', :require => 'pg'
Problem Solved!!! :-) Enjoy!
One possibility is that the rake binary that you are running is from another ruby/gem environment and that it doesn't have access to the gems that you've installed.
If you have more than one version of ruby installed, try running which gem and then which rake to see if they are being run from the same bin directory. For example, on my machine both binaries are executed from bin directories under the same Ruby install:
/Users/scott/.rvm/rubies/ruby-1.9.2-p136/bin/gem
/Users/scott/.rvm/gems/ruby-1.9.2-p136/bin/rake
If you only have one ruby version installed on your system, then this isn't the answer!

Resources