no such file to load -- redis-namespace - namespaces

I am working on Rails 2.3.8. I have following in my environment.rb
config.gem "redis"
config.gem "redis-namespace", :lib => "redis/namespace"
When I list my redis gems then I see:
redis (2.0.3)
redis-namespace(0.7.0)
When I run rake gems:install then I get an error that says:
no such file to load -- redis-namespace
Shouldn't requiring "redis/namespace" solve the issue? Can anyone please help me with this?

It sounds as if rake gems:install depends on the very gem it is trying to install.
Try using rails_gem_install or bundler instead.

Related

Why does Rails say "cannot load such file mysql/mysql_api"?

I was following a tutorial on lynda.com (RoR 3: Section 6, ep. 3) and after installing MySQL and running:
rake db:schema:dump
I got:
rake aborted! cannot load such file mysql/mysql_api
C:/Sites/demo/config/application.rb:7:in '<top <required>>'
C:/Sites/demo/Rakefile:4:in 'require'
C:/Sites/demo/Rakefile:4:in '<top <required>>'
I did copy:
libmySQL.dll
To:
C:\RailsInstaller\Ruby1.9.3\bin
and I also tried uninstalling and installing the mysql gem a couple of times.
I think your problem is similar to cannot load such file -- mysql/mysql_api.
If you are trying to access 64 bit MySQL from 32 bit Ruby then you might encounter this.

NameError: cannot load Java class com.mysql.jdbc.Driver

I'm using JRuby 1.7.2, along with DataMapper, and I'm getting an error I can't find an answer to.
I'm just testing out DataMapper along with MySQL 5.5 to see if it will run fine when I build around it. Here's the file I'm testing:
require "data_mapper"
require "keys"
DataMapper.setup(:default, "mysql://#{$user}:#{$pass}#localhost/test_db")
And when I run this, I get the error:
NameError: cannot load Java class com.mysql.jdbc.Driver
And it points to the DataMapper.setup line.
My Gemfile should be alright:
source :rubygems
gem "sinatra"
gem "trinidad"
gem "data_mapper"
# do a `sudo apt-get install libmysqlclient-dev` first
gem "dm-mysql-adapter"
gem "jdbc-mysql"
Is there anything I'm missing? I have MySQL set up with a user/pass locally already.
This is a common error when running JDBC clients for MySQL. You need to make sure you have mysql-connector-java-bin.jar on the classpath. You can download it from here.
I'm using Rails 3.2.9 and to solve the problem I added this to my application.rb
if defined? JRUBY_VERSION
require 'jdbc/mysql'
Jdbc::MySQL.load_driver
end
actually, the correct answer is to work-around an incompatibility between 5.1.13 and 5.1.22 !
jdbc-mysql gem already contains the mysql-connector.jar it just ain't auto-loading anymore :
https://github.com/jruby/activerecord-jdbc-adapter/tree/master/jdbc-mysql (read the README)
you can also force the driver to auto-load using a Java system property e.g. from a cmd line :
jruby -J-Darjdbc.mysql.autoload=true -S rake ...
I had the same error when trying to use a mysql database from jruby/rails4. In my case this line was missing from ./Gemfile:
gem 'jdbc-mysql'

can't run migration

I run
rake db:create
and getting strange error
rake aborted!
126: ═х эрщфхэ єърчрээ√щ ьюфєы№. - C:/Ruby192/lib/ruby/gems/1.9.1/gems/mysql2-
0.3.11-x86-mingw32/lib/mysql2/1.9/mysql2.so
I tried to reinstall bundler.
Is it gem problem ?
To solve this problem, reference to the following link:
http://maxivak.com/installing-mysql2-gem-on-ruby-1-9-2-and-rails-3-0-5-on-windows/
You need to include mysql-connector through the Rails DevKit.

How to use ActiveRecord in a JRuby script outside Rails?

I would like to use JRuby to run a script which populates a database. I am already running JRuby/Rails for a Rails server in another application, and this setup works.
I ran the script (foo.rb) fine until I tried to include the ActiveRecord gem in line 2. The code looks like this:
require 'rubygems'
require 'activerecord'
require 'csv'
nf=[]
Dir["./*.*"].each{|f|nf<<f if File::ctime(f) + 600 > Time.now}
nf.each{|f| p f.inspect}
The error I get looks like this:
unix> jruby --1.9 foo.rb
LoadError: no such file to load -- activerecord
require at org/jruby/RubyKernel.java:1047
require at /home/user/.rbenv/versions/jruby-1.6.4/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36
(root) at foo.rb:2
My gem listing includes all of rails 3.0.10, activerecord 3.0.10, activerecord-jdbc-adapter 1.2.0, activerecord-jdbcmysql-adapter 1.2.0.
I also have an environment variable (JRUBY-OPTS=--1.9) which tells JRuby to run version 1.9 when I use Rails.
What am I missing to get JRuby 1.9 to run with ActiveRecord 3.0.10 to hit a MySQL database?
Change your require to:
require 'active_record'

Rails keeps trying to use SQLite , despite that I've configured MySQL for my project

I setup my rails project "tracks" using:
$ rails --database=mysql tracks # OK
$ cd tracks
$ vim config/database.yml # correct using mysql adapter, added password spec
$ rake db:create RAILS_ENV='development' # OK
$ rake db:migrate # OK
$ ruby script/generate scaffold user name:string password:string email:string url:string # OK
$ rake db:migrate # OK, creates table
$ ruby script/server # OK, starts WEBrick
I open up the thing in a web browser:
http://localhost:3000 # correctly shows the rails welcome splash
I navigate to
http://localhost:3000/users/new
and get a huge slew of errors:
ActiveRecord::StatementInvalid in UsersController#index
SQLite3::SQLException: no such table: users: SELECT * FROM "users"
RAILS_ROOT: /home/drew/tracks/trunk/tracks
Application Trace | Framework Trace | Full Trace
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:188:in `log'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in `execute'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:372:in `catch_schema_changes'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:132:in `execute'
vendor/rails/activerecord/lib/active_record/connection_adapters/sqlite_adapter.rb:275:in `select'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb:7:in `select_all_without_query_cache'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:81:in `cache_sql'
vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/query_cache.rb:60:in `select_all'
vendor/rails/activerecord/lib/active_record/base.rb:635:in `find_by_sql'
vendor/rails/activerecord/lib/active_record/base.rb:1490:in `find_every'
vendor/rails/activerecord/lib/active_record/base.rb:589:in `find'
app/controllers/users_controller.rb:5:in `index'
wtf? Why is ruby still trying to use SQLite? database.yml has zero mention of SQLite.
Thanks
Couldn't figure it out. I ended up reinstalling the OS on the VM and trying again and it worked.
FYI: Do not install rubygems from a package manager like apt-get. Compile it from source or it will all end in tears.
Had this problem, I found all of the files using "find . | xargs grep 'sqlite3' -sl then replaced all of the yml and rb files it found then restarted the server.
Unfortunately, I don't know which (if any, as it may have been the server restart) solved the issue, but now I'm on and up.
Hope that helps someone, however 'hacky'.
Quick Fix that i've used is...
When i start a project a specify the -d for database
rails -d mysql ProjectName
Which builds the database.yml file for mysql
hope this helps.
As odd as it might sound, try clearing your browser's cookies. I had a similar problem moving from sqlite to postgresql and vice versa. It turns out the stored cookie or session was somehow making the server get stuck in using the old database. If this works then you'll want to take steps on your server to invalidate any existing cookies in your users' browsers.
Don't mean to necro, but if someone runs onto this problem, edit your config/database.yml file, and remove the line that says << default from the production section. What this is doing is loading the default environment first, so Passenger loads it instead of whatever else you've configured.