My apologize in advance for having used a robot translator, a small help to save a little time:
Over the next few articles i will use jruby 1.3.1 with Rails 2.3.3 and this is an opportunity to write two lines about how to configure the system.
By the way, the system used is a virtualized windows xp, java sdk 6, Glassfish as application server and javadb.
Download and install the java sdk, at the moment we are at version 6 update 14.
There is also the sdk with NetBeans, an excellent IDE to manage projects ruby on rails. It could be an opportunity to try it. The package also includes the application server Glassfish V3.
Now we download and install jRuby, atm we are at version 1.3.1.
Installation is simple: unpack the zip in a path like C:rubyjruby-131
Let’s set the environment variables, right click on “My Computer” icon on the desktop -> Properties -> select the tab “Advanced” -> click on “environment variables”.
- Add to the PATH variable the path to the bin folder where we installed jruby, for example C:rubyjruby-131bin.
- Set the environment variable JAVA_HOME. In the “system variables” -> “New” -> as the name “JAVA_HOME” value as the installation path dell’sdk for example C:ProgrammiJavajdk1.6.0_14
It is not necessary to restart the operating system, we test the result:
C:>jruby -v
jruby 1.3.1 (ruby 1.8.6p287) (2009-06-15 2fd6c3d) (Java HotSpot(TM) Client VM 1.6.0_14) [x86-java]
Eureka! Now we’re ready to use jruby, jirb and gem. If in your system there is also classic ruby you may specify jruby-S to recall gem otherwise you can also put jruby path in the last position inside environment variable. Ok, now we can install rails 2.3.3:
C:>jruby -S gem install rails
Successfully installed activesupport-2.3.3
Successfully installed activerecord-2.3.3
Successfully installed actionpack-2.3.3
Successfully installed actionmailer-2.3.3
Successfully installed activeresource-2.3.3
Successfully installed rails-2.3.3
6 gems installed
Installing ri documentation for activesupport-2.3.3...
Installing ri documentation for activerecord-2.3.3...
Installing ri documentation for actionpack-2.3.3...
Installing ri documentation for actionmailer-2.3.3...
Installing ri documentation for activeresource-2.3.3...
Installing ri documentation for rails-2.3.3...
Installing RDoc documentation for activesupport-2.3.3...
Installing RDoc documentation for activerecord-2.3.3...
Installing RDoc documentation for actionpack-2.3.3...
Installing RDoc documentation for actionmailer-2.3.3...
Installing RDoc documentation for activeresource-2.3.3...
Installing RDoc documentation for rails-2.3.3...
We install the jdbc adapter to connect to Java DB (i don’t use jruby-S anymore, in my system is not necessary):
C:>gem install activerecord-jdbcderby-adapter
Successfully installed activerecord-jdbc-adapter-0.9.1
Successfully installed jdbc-derby-10.4.2.0
Successfully installed activerecord-jdbcderby-adapter-0.9.1
3 gems installed
Installing ri documentation for activerecord-jdbc-adapter-0.9.1...
Installing ri documentation for jdbc-derby-10.4.2.0...
Installing ri documentation for activerecord-jdbcderby-adapter-0.9.1...
Installing RDoc documentation for activerecord-jdbc-adapter-0.9.1...
Installing RDoc documentation for jdbc-derby-10.4.2.0...
Installing RDoc documentation for activerecord-jdbcderby-adapter-0.9.1...
Then install the gem for Glassfish:
C:>gem install glassfish
Successfully installed rack-1.0.0
Successfully installed glassfish-0.9.5-universal-java
2 gems installed
Installing ri documentation for rack-1.0.0...
Installing ri documentation for glassfish-0.9.5-universal-java...
Installing RDoc documentation for rack-1.0.0...
Installing RDoc documentation for glassfish-0.9.5-universal-java...
We are ready, we create a new project:
C:>rails ProvaArticolo
… in the database’s configuration file we use:
# config/database.yml # JavaDB Setup # # You may need to copy derby.jar into # TODO: location C:rubyjruby-131lib # With Java SE 6 and later this is not necessary. development: adapter: derby database: db/development.db # Warning: The database defined as 'test' will be erased and # re-generated from your development database when you run 'rake'. # Do not set this db to the same as development or production. test: adapter: derby database: db/test.db # Warning: The database defined as 'test' will be erased and # re-generated from your development database when you run 'rake'. # Do not set this db to the same as development or production. production: adapter: derby database: db/production.db # Warning: The database defined as 'test' will be erased and # re-generated from your development database when you run 'rake'. # Do not set this db to the same as development or production.
Let us start the server, from the prompt inside our application’s directory:
C:ProvaArticolo>glassfish
Starting GlassFish server at: 127.0.0.1:3000 in development environment...
Writing log messages to: C:/ProvaArticolo/log/development.log.
Press Ctrl+C to stop.
At http://localhost:3000/ should see the welcome page.
Now stop the server with Ctrl + C db and create the environment in development:
C:ProvaArticolo>rake db:create
(in C:/ProvaArticolo)
db/development.db already exists
We create something within the database, we start with the source of rails:
C:ProvaArticolo>jruby script/generate scaffold article name:string body:text
create app/models/
exists app/controllers/
exists app/helpers/
exists app/views/articles
create app/views/layouts/
create test/functional/
create test/unit/
create test/unit/helpers/
create public/stylesheets/
create app/views/articles/index.html.erb
create app/views/articles/show.html.erb
create app/views/articles/new.html.erb
create app/views/articles/edit.html.erb
create app/views/layouts/articles.html.erb
create public/stylesheets/scaffold.css
create app/controllers/articles_controller.rb
create test/functional/articles_controller_test.rb
create app/helpers/articles_helper.rb
create test/unit/helpers/articles_helper_test.rb
route map.resources :articles
dependency model
exists app/models/
exists test/unit/
create test/fixtures/
create app/models/article.rb
create test/unit/article_test.rb
create test/fixtures/articles.yml
exists db/migrate
create db/migrate/20090729171105_create_articles.rb
and create the table:
C:ProvaArticolo>rake db:migrate
(in C:/ProvaArticolo)
== CreateArticles: migrating =================================================
-- create_table(:articles)
-> 0.0700s
-> 0 rows
== CreateArticles: migrated (0.0700s) ========================================
Finally remove the index.html file from inside the public folder and create the initial route:
#configroutes.rb map.root :controller => "articles"
Reboot the server and at http://localhost:3000/ this time we should see a list of articles.
If I don’t have forgotten something, jruby on rails is ready, enjoy!
English
Italiano