Could not load 'active_record/connection_adapters/postgresql_adapter' - ruby

I have a Sinatra app using Postgres via Activerecord. I'm using RVM on a Mac and a number of gems including:
activerecord
activesupport
When I run the server (thin), I get an error:
Could not load 'active_record/connection_adapters/postgresql_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.
The adapter is set to postgresql in the config, and I've checked my RVM and paths: My Gem install path is set properly, and I can see the appropriate gems installed properly, and the specific adapter is there too, so really not sure what could be happening or how to further troubleshoot this?
Using Ruby 2.0.0-p598, activerecord and activesupport 4.1.4
--
Further debugging attempts:
ruby -v
ruby 2.0.0p598 (2014-11-13 revision 48408) [x86_64-darwin14.0.0]
which ruby
/Users/user/.rvm/rubies/ruby-2.0.0-p598/bin/ruby
gem env (relevant parts):
EXECUTABLE DIRECTORY: /Users/user/.rvm/gems/ruby-2.0.0-p598/bin
GEM PATHS:
/Users/user/.rvm/gems/ruby-2.0.0-p598
/Users/user/.rvm/gems/ruby-2.0.0-p598#global
SHELL PATH:
/Users/user/.rvm/gems/ruby-2.0.0-p598/bin
/Users/user/.rvm/gems/ruby-2.0.0-p598#global/bin
/Users/user/.rvm/rubies/ruby-2.0.0-p598/bin
ls $GEM_HOME/gems
activerecord-4.1.4
activesupport-4.1.4
Really at a loss for what else I can look into
database.yml
development:
adapter: postgresql
database: example_db
username: example_user
password: example_password
host: localhost

A next debugging step I took was to try using rvm to install a whole new version of ruby. This worked, so I used rvm to completely remove my old version of ruby with rvm remove 2.0.0-p598 and reinstall it again rvm install 2.0.0-p598.
I still have no idea what may have happened, but perhaps somehow something in the gem caches/builds were corrupted, so if anyone runs into a weird error like this where everything is in place but still doesn't work, try clearing everything with rvm and reinstalling.

Related

"rubygem mysql error: gem is not loaded" after CentOS upgrade

I am upgrading a system from EL 6 to EL 7. We have an application that uses ruby to setup a MySQL database. I know very, very little about ruby and gems, so I'm struggling getting this going. Under EL 6, the setup process works properly. Under CentOS 7, I get the following error when processing the rakefile:
Specified 'mysql' for database adapter, but the gem is not loaded. Add
gem 'mysql' to your Gemfile
Under 6, I don't see any MySQL gem files installed using gem list, but the setup process works fine and generates our database properly.
Under 7, I can manually run: gem install mysql --with-mysql-config=/usr/lib64/mysql/mysql_config.
Then, the setup script works.
I am installing most of the required gems/ruby applications via rpm.
I have:
ruby-2.0.0.648-29.el7.x86_64
rubygem-rake-0.9.6-29.el7.noarch
rubygem-activesupport-4.2.5.2-2.fc24.noarch
rubygems-2.0.14.1-29.el7.noarch
rubygem-activemodel-4.2.5.2-1.fc24.noarch
rubygem-activerecord-4.2.5.2-1.fc24.noarch
ruby-mysql-2.8.2-1.el7.x86_64
ruby-mysql creates /usr/local/lib64/ruby/site_ruby/mysql.so.
Is the mysql.so library what provides the MySQL adapter or is there something else that effectively provides the mysql gem? It's confusing that I don't have to do anything in EL 6 but have to install it specifically in EL 7.
Is this a pathing issue or a major change in source? I'm obviously pulling in the activesupport and activerecord rpms from Fedora, so I suppose there could be a conflict there, but it's very hard to tell.
My database.yml file looks like this:
adapter: mysql
encoding: utf8
database: mydatabase
username: root
password:
host: 127.0.0.1
port: 3306
Try use the mysql2 gem instead:
In your Gemfile:
gem 'mysql2'
and database.yml:
adapter: mysql2
Hope that would help.
So I'm not sure why there was never a gemfile in the original script. As mentioned in my OP, a basic solution was to run gem install mysql, but that was weird because previously it wasn't necessary.
What I think was happening:
Under EL6, the ruby-mysql rpm was putting the mysql.so in the proper location and basically issuing a gem install command. The EL7 version I have was not calling the proper setup macros in the rpm.
What I did to fix this:
i used gem2rpm (such a great rpm/package) to generate the rubygem-mysql spec file.
https://github.com/fedora-ruby/gem2rpm
gem2rpm --fetch mysql (to get the gem)
gem2rpm -T > rubygem-mysql.spec.template
gem2rpm -t rubygem-.spec.template mysql-2.9.1.gem > rubygem-mysql.spec
You have to modify the spec file a bit after it's generated, then use that to spec template to properly build the spec file for your needs.
Then just use rpmbuild to actually make the rpm/srpm.
gem list now shows mysql in there and the setup script works.

sinatra app on localhost via unicorn: syntax error

I have a Sinatra app that I continually upgrade (local only, at the moment). Problem being that I know nothing at all about Ruby — my friend made me the app and it's worked beautifully for over almost a year.
To see the site on localhost, I do this:
bundle exec unicorn -l 9000
I don't understand this, haven't needed to. I know I'm using the unicorn gem to run the app directed at port 9000 (due to an old printer conflict).
Today, I get this error:
in `evaluate': compile error (SyntaxError)
syntax error, unexpected ':', expecting $end
which refers to line 16 of my gem file, the sinatra-contrib gem:
gem "sinatra-contrib", require: "sinatra/reloader"
I've never had this error before. Haven't ever touched the gem file, and it's been working for a year. The only thing I can think I've done recently that may have affected my environment is installing a gemset called Wordless:
rvm use 1.8.7#wordless --create --default && gem install therubyracer sprockets compass coffee-script thor yui-compressor && rvm wrapper 1.8.7#wordless wordless compass ruby
I'd appreciate insights, and hopefully I can start to learn a thing or two about managing ruby gems. Thanks.
You were using Ruby 1.9 before. The line you referenced is in 1.9 format, which Ruby 1.8 does not understand.
When you installed Wordless you said:
rvm use 1.8.7#wordless --create --default
This made Ruby 1.8.7 your default interpreter. To switch back to whatever you used before do:
rvm list rubies
And then:
rvm use [the 1.9.x you found in the list above] --default

Why I can't install postgresql with rails 4.0.0.rc1 (ruby 2.0)

first time on forum so i will try to be as specific as one can be, sorry for any possible typos ok?
I am relatively new to rails (less than a year), and i want to make a default project to work with it. I have always used sqlite3 in development and pg in production (heroku), but now i want to make things right (i've encountered problems with sqlite3 running ok but pg not) and use both pg in production and devlop.
I have spent 2 days searching foruns and all the anwsers are old or other versions/other OS.
I'll try to list the steps i took for setting up my stage:
Here my configs:
-OS: Windows 7 64x
-Editor: Aptana Studio
-PostGresql
-Rails 4.0.0.rc1
-Ruby 2.0
Download and Install postgresql-9.2.4-1-windows-x64
Set a default Password to postgresql
Create an Role "my_user" in postgresql with all privilegies
Create an testing database "rails_test"
Open Aptana Studio and init an new default project going to the project folder and than running "rails new . -d postgresql" for generate the new project.
Install the pg gem "gem install pg" "gem list" shows the pg gem correctly
configure "database.yml" for using the correct username and password
development:
adapter: postgresql
encoding: unicode
database: rails_test
pool: 5
username: my_user
password: 12345
Running some commands in ruby like "gem update", "bundle install"
then when i try to generate an model and use rake db:migrate i get the following error:
Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile.
and it's true if i run "bundle show pg" i get the message:
Could not find gem 'pg'. Did you mean pg?
If i open my gemfile the pg gem is there, but the bundler is not getting it !
Any ideias to help this little amateur?
TNX !
(Windows 7 x64, Ruby2.0.0p247-x64, Rails4.0.0, Postgresql 9.2.4 x64, pg 0.15.1, mysql2 0.3.11)
There seems to be a platform detection/verification problem with bundler. While what I did is a hack of the Gemfile.lock file (I know, I know...), I have a (hopefully) temporary solution:
Edit Gemfile.lock, and
Find the line for 'pg':
multi_json (1.7.7)
pg (0.15.1-x86-mingw32)
polyglot (0.3.3)
Copy the line, and modify the new copy to :
multi_json (1.7.7)
pg (0.15.1-x64-mingw32)
pg (0.15.1-x86-mingw32)
polyglot (0.3.3)
This is how the x64 version of the installed gem announces itself when you ask to list it (gem list pg).
For anyone who cares, the exact same problem was (sometimes) encountered with the mysql2 gem.
I had this problem and solved it by using the 32bit version of ruby rather than the 64bit. You need to make sure the devkit matches up to your version as well. So if you have the 64 bit version of that installed then that will need to be changed too.

installing sqlite3 for ruby

I've installed the latest version of ruby and mysql but still when i try and run something through aptana with 'requires 'rubygems' and 'requires 'sqlite3' i get the following appear in the console:
/home/carladessi/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in`require': cannot load such file -- sqlite3 (LoadError)
from /home/carladessi/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'from /home/carladessi/Documents/Aptana Studio 3 Workspace/Test/rubydb.rb:2:in `<main>'
The error you posted is for sqlite3 and not MySQL. I've not used Apatana Studio bit it looks as if it, or your program is requesting sqlite3, not MySQL. Check your Gemfile, if you have one, for sqlite3. Also check Apatana Studio requirements to see if it requires sqlite3.
Updated to reflect change in question:
It looks as though you're using RVM. Try the following from the terminal.
1.If you are using a Gemfile and bundler then on the terminal ensure you're executing your application with bundle exec. For instance:
bundle exec myapp.rb
Make sure that you are using the same gemset to which you installed sqlite3 with gem install sqlite.

"Could not find a valid gem in any repository" (rubygame and others)

I've been trying to install this 'rubygame' gem for some time, but whenever I use the command
gem install rubygame
it will give an error:
ERROR: Could not find a valid gem 'rubygame' (>= 0) in any repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ETIMEDOUT: Connection timed out - connect(2) (http://rubygems.org/latest_specs.4.8.gz)
I've also tried other gems but with similar results:
ERROR: Could not find a valid gem 'rake' (>= 0) in any repository
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ETIMEDOUT: Connection timed out - connect(2) (http://rubygems.org/latest_specs.4.8.gz)
I've already made sure I have an internet connection, and have already tried reinstalling both ruby and rubygems (currently using ruby 1.8, rubygems 1.7.2). Googling didn't help me at all. I would be very grateful if anyone can solve my problem. My sources list only shows http://rubygems.org
Check if you have "https://rubygems.org/" as a source to find gems at:
$ gem sources
*** CURRENT SOURCES ***
https://rubygems.org/
If not, you should be able to add it with
$ gem sources --add https://rubygems.org/
https://rubygems.org/ added to sources
Here are docs for the gem source command.
You can also add the source you want on the command whenever you have troubles using https, like this:
gem install GEMNAME --source http://rubygems.org
It's better to fix the SSL problem though.
are you behind any proxy?
check your browser for proxy that you might use:
execute the command: gem install xxx --http-proxy=http://user:password#server and you should be good to go.
You don't have an Internet connection to rubygems.org.
This happens sometimes if the site is down or blocked.
This command can show you if your connection has a way to reach rubygems.org:
traceroute rubygems.org
Maybe you should try
gem list -r
then
gem install -r rubygame
Also note that with rvmon MacosX (Lion in my case) you should install ruby-1.9.3-p194 (for Xcode 4.x compiler considerations) then
rvm rubygems current
and in my case I had to use
rvm use ruby-1.9.3-p194#global
(which contains bundler, rake, rubygems-bundlerand rvm)
and not
rvm use ruby-1.9.3-p194
(which is empty)
Can you post your versions?
ruby -v
#=> ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-linux]
gem -v
#=> 1.8.19
If your gem command is not current, you can update it like this:
gem update --system
To see if you can connect to rubygems.org using Ruby:
require 'net/http'
require 'uri'
puts Net::HTTP.get URI.parse('https://rubygems.org')
If yes, that's good.
If no, then somehow Ruby is blocked from opening a net connection. Try these and see if any of them work:
curl https://rubygems.org
curl https://rubygems.org --local-port 1080
curl https://rubygems.org --local-port 8080
env | grep -i proxy
If you're using a company machine, or within a company firewall, or running your own firewall, you may need to use a proxy.
For info on Ruby and proxies see
http://www.linux-support.com/cms/http-proxies-and-ruby/
I have fixed this issue using the proxy command option of gem install. It has the following format:
$ gem install --http-proxy http://201.187.107.19:8080 rubygame
Note, the IP address and the port number refers to a proxy. You should search for a proxy list and use one of the proxies there.
This is site with proxies: http://www.cybersyndrome.net/pla5.html
Also, I have to try 7 or 8 different proxies in order to succeed. Do not give up.
Use :
gem sources --add http://rubygems.org/
Do you want to add this insecure source? [yn] [YES]
then use
gem install sass
and done
I know this is a little late, but I was also having this issue a while ago. This is what worked for me:
REALLY_GEM_UPDATE_SYSTEM=1
sudo gem update --system
sudo gem install rails
Hope this helps anyone else having this issue :)
I have tried most of the solutions suggested here but I had no luck.
I found a solution that worked for me, which was manually updating the gemfile to 2.6.7.
The guide on how to do is in guides.rubygems.org: installing-using-update-packages
Download rubygems-update-2.6.7.gem to your C:\
Now, using your Command Prompt:
C:\>gem install --local C:\rubygems-update-2.6.7.gem
C:\>update_rubygems --no-ri --no-rdoc
After this, gem --version should report the new update version (2.6.7).
You can now safely uninstall rubygems-update gem:
C:\>gem uninstall rubygems-update -x
Removing update_rubygems
Successfully uninstalled rubygems-update-2.6.7
The reason why this did not work before was because server used certificates SHA-1, now this was updated to SHA-2.
For what it is worth I came to this page because I had the same problem. I never got anywhere except some IMAP stuff that I don't understand. Then I remembered I had uninstalled privoxy on my ubuntu (because of some weird runtime error that mentioned 127.0.0.1:8118 when I used Daniel Kehoe's Rails template, https://github.com/RailsApps/rails3-application-templates [never discovered what it was]) and I hadn't changed my terminal to the state of no system wide proxy, under network proxy.
I know this may not be on-point but if I wound up here maybe other privoxy users can benefit too.
check your DNS settings ...I was facing similar problem ... when I checked my /etc/resolve.config file ,the name server was missing ... after adding it the problem gets resolved
This worked for me to bypass the proxy definitions:
1) become root
2) gem install -u gem_name gem_name
Hope you can work it out
I tried to install a gem which is for JRuby only, running into the same error. Using jruby's command worked then:
jruby -S gem install some_jruby_gem
If you are running behind the any firewall(if firewall blocking gem installation). just try following command it works.
gem install --http-proxy http://username:pwd#server:port gem
Make sure you type the command from the "App" Directory
It is a permission issue.
try with sudo

Resources