dcsimg
July 16, 2018
Hot Topics:

JRuby on Rails with Nine Lives: Running a JRuby on Rails Application on Tomcat

  • July 31, 2007
  • By Dominic Da Silva
  • Send Email »
  • More Articles »

Configuring the Database

Next, you need to tell your JRuby on Rails app to use ActiveRecord-JDBC and what database you will be using. Within the railswartest directory, edit the config/environment.rb file and add the following just before the line containing Rails::Initializer.run do |config|:

if RUBY_PLATFORM =~ /java/
   require 'rubygems'
   gem 'ActiveRecord-JDBC'
   require 'jdbc_adapter'
end



Click here for a larger image.

Figure 7: Configuring JRuby on Rails app to use ActiveRecord-JDBC

This tells Rails that, if it detects that it is running on Java (in other words, JRuby) to load the ActiveRecord-JDBC gem.

Now, configure your JDBC driver. Within the railswartest directory, edit the config/database.yml file and edit the development: and production: configurations to contain the following:

development:
   adapter: jdbc
   driver: com.mysql.jdbc.Driver
   url: jdbc:mysql://localhost:3306/railswartest
   username: <username>
   password: <password>

production:
   adapter: jdbc
   driver: com.mysql.jdbc.Driver
   url: jdbc:mysql://localhost:3306/railswartest
   username: <username>
   password: <password>



Click here for a larger image.

Figure 8: Configuring the JRuby on Rails app development and production database connections

I am using a database named railswartest, which I created using the MySQL Query Browser:



Click here for a larger image.

Figure 9: Creating MySQL database 'railswartest' using MySQL Query Browser





Page 3 of 8



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.

Sitemap

Thanks for your registration, follow us on our social networks to keep up-to-date