Saturday, December 29, 2012

rails 3.2 with jruby and mysql with rvm in ubuntu

If was trying to migrate one of the app from ruby to jrby to try out the threading benifits.

this wasn't an easy task :D

well the gem dependency did not create a big issue.

the problem came when connecting to mysql with jdbc driver
I had replaced

 gem 'mysql2'

 gem 'activerecord-jdbcmysql-adapter'

in Gemfile

But it refused to load the driver saying :

"The driver encountered an unknown error: cannot load Java class com.mysql.jdbc.Driver'

I searched but Google could not answer me :(

then I started looking into activerecord-jdbsmysl-adapter gem and came upon the the file 

activerecord-jdbc-adapter / activerecord-jdbcmysql-adapter / lib / active_record / connection_adapters /jdbcmysql_adapter.rb 

I just copy pasted the code in a application.rb config with a condition if jruby used just after the bundler code

if defined?(JRUBY_VERSION)
  require 'jdbc/mysql'
  Jdbc::MySQL.load_driver(:require) if Jdbc::MySQL.respond_to?(:load_driver)

and boom it worked...!!!

I don't know why it did not load it even if it was included in Gemfile.

but at last I was able to run the app wit jruby and rails. Woaaahhhh..

Monday, December 10, 2012

Send devise compatible forgot password mail through action mailer in rails

To have multiple forgot password templates and send it through mailer in rails it is quite easy