JRuby cannot use the adapter I installed - ruby-on-rails

I used rvm to install jruby (1.5.6) and installed all my gems just fine. I can run simple rails tasks like
script/runner 'puts 1'
and the output is fine. AS SOON as I hit the database I get an error. I have uninstalled/reinstalled the activerecord-jdbcmysql-adapter gem, Jruby, rvm, JAVA_JDK. I have set the JRUBY_HOME and JAVA_HOME correctly, but it seems like nothing works.
Any thoughts?
As far as I know, I have Java JDK 1.6.0 and 1.5.0 installed. IT is currently pointed to 1.6.0. But since all the other gems installed correctly, I am assuming this is something else entirely.
I am on EC2 with Ubuntu 10.04 (64 bit)
Ruby 1.9.2 with RVM works great!
nohup: ignoring input
/opt/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:76:in establish_connection': Please install the jdbcmysql adapter:gem install activerecord-jdbcmysql-adapter(no such file to load -- active_record/connection_adapters/jdbcmysql_adapter) (RuntimeError)
from /opt/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:60:inestablish_connection'
from /opt/jruby/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/connection_adapters/abstract/connection_specification.rb:55:in establish_connection'
from /opt/jruby/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/initializer.rb:438:ininitialize_database'
from /opt/jruby/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/initializer.rb:141:in process'
from /opt/jruby/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/initializer.rb:113:inrun'
from /home/tesmar/rails/statsheet/config/environment.rb:19
from /home/tesmar/rails/statsheet/config/environment.rb:39:in require'
from /opt/jruby/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/commands/runner.rb:39
from /opt/jruby/lib/ruby/gems/1.8/gems/rails-2.3.8/lib/commands/runner.rb:3:inrequire'
from script/runner:3

As the error message says, you need to install the activerecord-jdbcmysql-adapter gem.
It is possible that your execution environment is different from your rvm environment. I've seen this happen with IDEs such as NetBeans.

How do your gemfile look like?
Mine looks like this and work:
source 'http://rubygems.org'
gem 'rails', '3.0.4'
platforms :ruby do
gem 'mysql2'
end
platforms :jruby do
gem 'activerecord-jdbc-adapter'
gem 'jdbc-mysql', :require => false
end

If you are going back and forth between jRuby and MRI, you can add something like this to your Gemfile too:
if defined?(JRUBY_VERSION)
gem 'jdbc-mysql'
gem 'activerecord-jdbc-adapter'
gem 'activerecord-jdbcmysql-adapter'
gem 'warbler'
else
gem 'mysql'
gem 'mongrel'
end
Then, in your database.yml add something like this:
development:
adapter: <%= defined?(JRUBY_VERSION) ? 'jdbcmysql' : 'mysql' %>

I figured it out. I had to download the JAR file, after copying manually all the rb files into the active record gem (the rb files from the activerecord-jdbcmysql and activerecord-jdbc gems). I then put the JAR file in the /opt/jruby/lib directory and it works! Woohoo!

Related

How to solve tzinfo error on ruby on rails?

Trying to learn ruby on rails and I keep coming up with this error:
rails aborted!
TZInfo::DataSourceNotFound: tzinfo-data is not present. Please add gem 'tzinfo-data' to your Gemfile and run bundle install
Caused by:
TZInfo::DataSources::ZoneinfoDirectoryNotFound: None of the paths included in TZInfo::DataSources::ZoneinfoDataSource.search_path are valid zoneinfo directories.
D:/RubyRails/ineedhelp/config/environment.rb:5:in `<main>'
Tasks: TOP => app:template => environment
(See full trace by running task with --trace)
rails turbo:install stimulus:install
You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem.
You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem.
when I'm starting a new project
I'm using Windows 10 64bit.
Though I keep adding gem "tzinfo-data" to my application's GemFile AND use gem install tzinfo in cmd, it doesn't work.
It may work temporarily but the error keeps showing up each time I'm trying to insert another command in cmd (like rails s).
gem "tzinfo-data", platforms: %i[ mingw mswin x64_mingw jruby ]
This line is already in my GemFile when the error pops up.
I already tried several solutions found online.
Just remove the platform part
This is how your gem name should look like
gem "tzinfo-data"

Add Gem 'wdm' to your GemFile

Error
I have tried running the following command in git bash
rails g scaffold_controller oragnizationsController
And I get the error in the picture.
I have tried multiple solutions:
1- Tried running
gem install wdm
2- Tried running
bundle install
3- I have tried adding
gem 'wdm', '~> 0.1.0'
and
gem 'wdm', '~> 0.1.1'
since I read that 0.1.0 ain't working anymore.
But the problem hasn't been solved yet. I am using windows 10, ruby 2.3.3, rails 5.1.4
Uninstall wdm gem and put it to the gemfile like this:
gem 'wdm' if Gem.win_platform?
Or like the error tells you
The message about wdm is misleading here. It seems to be just a notice/warning.
If you look closer, you'll see that the actual error message is printed in the line below that. It says:
cannot load such file -- bcrypt_ext (LoadError)
Then see here: Ruby on windows causes error Cannot load such file bcrypt_ext

LoadError: cannot load such file -- bcrypt_ext on Windows 2008 x64 server

I upgraded my environment from Ruby 2.0.0 to 2.2.3.
I also upgraded (overwrite) DevKit, and re-run ruby dk.rb install.
I removed Gemfile.lock and ran bundle install to start with a brand new environment. Everything looks ok, but I get the error:
E:\Projects\development\Stairs>rake db:migrate
rake aborted!
LoadError: cannot load such file -- bcrypt_ext
E:/Projects/development/Stairs/config/application.rb:7:in `<top (required)>'
E:/Projects/development/Stairs/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- 2.2/bcrypt_ext
E:/Projects/development/Stairs/config/application.rb:7:in `<top (required)>'
E:/Projects/development/Stairs/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
I first had the same issue with Nokogiri, which I solved using this solution : Nokogiri load error
using Juloi Elixir's solution and installing Nokogiri from a local copy.
But I don't feel like doing this foreach gem! It looks like ruby is searching the gem using a ./ or ./2.2 path, while gems are stored in a ./2.2.0 path. Is this configurable?
How can I solve this issue?
Note: Gemfile contains gem 'bcrypt', '~> 3.1.10'
Thanks!
I spent an entire hour fixing this, just now.
Well what I did was I followed some advice online to do a
gem install bcrypt --platform=ruby
And then, it worked in irb.
irb(main):001:0> require 'bcrypt'
=> true
Later when I had to do a bundle install, for some odd reason rails installed another bcrypt and the error was back. So I had two folders in my gem root.
bcrypt-3.1.10
bcrypt-3.1.10-x64-mingw32
So, since the first folder was the one that got built with the devkit, and it works. I deleted the contents of the second folder and copied the contents of the first into it.
Seems to be working as I'm writing this.
Solution was here: bcrypt-ruby#github:
Rebuild locally the bcrypt gem:
Change to the gem directory \Ruby22-x64\lib\ruby\gems\2.2.0\gems\bcrypt-3.1.10-x64-mingw32\ext\mri>
Run ruby extconf.rb
Run make
Run make install
Note that this works only if your DevKit environment is correctly setup (run devkitvars.bat).
#user1185081 's solution worked for me in a windows machine. I ran following commands and worked like magic:
$ cd C:\RailsInstaller\Ruby2.2.0\lib\ruby\gems\2.2.0\gems\bcrypt-3.1.10-x86-mingw32\ext\mri
$ ruby extconf.rb
$ C:\<DevKit Path>\devkitvars.bat (assuming you have devkit installed)(Ran this instead of running "make" because it was not recognized as an internal or external command)
$ make install
What worked for me on Windows 7:
gem uninstall bcrypt to uninstall all versions of bcrypt, including those listed as dependencies
gem install bcrypt to reinstall
bundle install
In my case, a designating of the old version to bcrypt in Gemfile was a cause of the error. I removed a designating of the version and run bundle update bcrypt, then it was settled.
Here is the solution worked for me:
C:\> gem uninstall brcypt
C:\> gem install --no-ri --no-rdoc bcrypt
C:\> cd (path to gems root)\bcrypt-3.1.7-x86-mingw32\ext\mri
C:\(path to gems root)\bcrypt-3.1.7-x86-mingw32\ext\mri> ruby extconf.rb
C:\(path to gems root)\bcrypt-3.1.7-x86-mingw32\ext\mri> make
C:\(path to gems root)\bcrypt-3.1.7-x86-mingw32\ext\mri> make install
I had the same problem:
cannot load such file — bcrypt_ext
Windows 8.1 64bit
ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
Rails 5.1.4
My solution:
gem uninstall bcrypt-ruby
gem uninstall bcrypt
gem install bcrypt –platform=ruby
added this whole line to Gemfile:
gem 'bcrypt', git: 'https://github.com/codahale/bcrypt-ruby.git', :require => 'bcrypt'
bundle install
This works for me, add this to your gems file:
gem 'bcrypt', '~> 3.1.7', platform: :ruby
This process is for windows:
The problem is with the programs installed on the system.
Uninstall all rails programs:
All Ruby programs.
RailsInstaller.
Removes all files that have been able to uninstall, you have to do it manually inside:
C:\RailsInstaller
Install de ruby version 2.2 from:
http://railsinstaller.org/en
Wait a moment and it's already to go.
MarlonJon.es

Connect rails to Sql Server

I am trying to connect Rails to Sql Server so I need to use an Sql Server adaptor. I installed it by downloading the adaptor locally from github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git. After that I did: gem build activerecord-sqlserver-adapter.gemspec in the directory where I had the spec file, followed by gem install <name of gem that was just built>.
After that, I added this line in the gemfile:
gem 'activerecord-sqlserver-adapter', :path => 'downloads/activerecord-sqlserver-adapter-master\activerecord-sqlserver-adapter-master' , then I ran a bundle install from the project root.
The error is:
Bundler could not find compatible versions for gem "activerecord": In
Gemfile: rails <=4.1.6> x86-mingw32 depends on activerecord <=4.1.6>
x86-mingw32
activerecord-sqlserver-adapter <>=0> x86-mingw32 depends on
activerecord <4.0.0>
What is strange is rails -v doesn't return the rails version although I just installed it.
Instead it throws:
Could not find gem 'tzinfo-data <>=0> x86-mingw32 in the gems available on this machine
Run bundle install to install missing gems
I should specify we are compulsed to use proxies at work
Every few month I keep checking to see if the Sql Server connection is improved/easier to perform with Rails without adaptors and such, because I want to use Sql Server instead of PostgreSQL. No luck so far. Any help is much appreciated. Thanks
It looks like the gem that you are using only supports until rails 4.0.0 (the gemspec forces to be this version).
You might try to use that rails version to see what's going on.
To do so, in your Gemfile.rb you can try this:
gem 'rails', '4.0.0'
gem 'activerecord-sqlserver-adapter', git: 'https://github.com/Desarrollo-CeSPI/activerecord-sqlserver-adapter.git'
and then run
bundle update rails # to force using the rails version specified in the gemfile
and then run
bundle install
BUT
The gem that you are using has not been updated since 22nd August 2013, so I would not expect it work.
The gem that you are using is a fork of the original project located at https://github.com/rails-sqlserver/activerecord-sqlserver-adapter
If you don't have anything to do with Desarrollo-CeSPI, then you should use the official gem to avoid some problems, for instance that the gem is not maintained anymore.

ruby - bundle install/update too slow

I just installed RVM, Ruby, Rails etc. on my virtual ubuntu 12.04 32bit running in a virtualbox. Now I encounter the problem that for my first rails project bundle install or bundle update takes very long time. Even when I create a new project with rails (which includes bundle install).
I use only the standard gems:
source 'https://rubygems.org'
gem 'rails', '3.2.12'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
group :development do
gem 'sqlite3', '1.3.5'
end
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '3.2.5'
gem 'coffee-rails', '3.2.2'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', :platforms => :ruby
gem 'uglifier', '1.2.3'
end
gem 'jquery-rails', '2.0.2'
I tried bundle install without any gems but gem 'rails', '3.2.12'. After that I typed again bundle install with all gems in my gemfile. It took me 10 minutes to check for dependencies. The output of --verbose is a mix of HTTP success and HTTP redirection.
Rails version: Rails 3.2.12
Ruby version: ruby 1.9.3p392 (2013-02-22 revision 39386)
Rvm: rvm 1.18.18
bundle version: Bundler version 1.3.2
I already searched fot a solution, but nothing helped.
I want to warn: There is a security purpose for using https over http. Try at first the other answers mentioned in this thread.
Changing https to http in my Gemfile did the magic. Before I have to create the project with rails new APP --skip-bundle
Bundler just got an update of parallel processing of gems.
gem install bundler --pre
will solve the problem in the best possible way for now.
Source
You can also use multiple jobs, it may improve a little bit
bundle install --jobs 8
Here is a tutorial about it
Bundler v1.12.x was released in 2016 and caused some users to experience slow bundle install issues.
In this instance staying with v1.11.2 is the best option (it's fast) until a fix is released.
It's worth heading over to Rubygems.org to try different versions of the bundler gem.
Check existing bundler versions, uninstall existing version, install version 1.11.2 example:
gem list | grep bundler
gem uninstall bundler -v existing-version-number
gem install bundler -v 1.11.2
A developer friendly method is to override the gem server with a faster alternative.
In our case, we can configure http as a mirror to address slow https connections:
bundle config mirror.https://rubygems.org http://rubygems.org
This allows you to keep original Gemfile configuration while still using faster http connections to fetch gems.
If you wanted to switch back to https:
bundle config --delete mirror.https://rubygems.org
bundle config has a default --global option. You can specify --local to limit configurations to local application folder.
Configuration is saved into global ~/.bundle/config and local .bundle/config.
If you're still seeing this issue with Bundler 1.12.5, you may want to try updating the OpenSSL used by your Ruby.
For me this went like so:
pmorse$ bundle --version
Bundler version 1.12.5
pmorse$ ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
OpenSSL 1.0.1j 15 Oct 2014
pmorse$ openssl version
OpenSSL 0.9.8zg 14 July 2015
pmorse$ brew info openssl
openssl: stable 1.0.2h (bottled) [keg-only]
[... more brew output ...]
pmorse$ rvm reinstall ruby-2.2.2 --with-openssl-dir=`brew --prefix openssl`
[... lots of rvm output ...]
pmorse$ ruby -ropenssl -e 'puts OpenSSL::OPENSSL_VERSION'
OpenSSL 1.0.2h 3 May 2016
This should make bundle quicker again without requiring you to go from https to http.
I know this may be basic answer but try to install developer tools from the main Ruby site. I have had a similar problem and it did work. Sometimes simple solutions are the best!
Good luck!

Resources