Skip to main content

TOTD #14: How to generate JRuby-on-Rails Controller on Windows (#9893)

Posted by arungupta on October 16, 2007 at 1:25 PM PDT

The current Rails Gem (version 1.2.5) gives an error when
creating a Controller in a JRuby-on-Rails application on Windows. It gives the
following error during controller creation as shown below:

C:/testbed/ruby/jruby-1.0.1/lib/ruby/1.8/pathname.rb:420:in 
`realpath_rec': No such file or directory -C:/testbed/ruby/jruby-1.0.1/samples/rails/hello/C:
(Errno::ENOENT)<br>
&nbsp;&nbsp;&nbsp; from C:/testbed/ruby/jruby-1.0.1/lib/ruby/1.8/pathname.rb:453:in
`realpath'<br>
&nbsp;&nbsp;&nbsp; from C:/testbed/ruby/jruby-1.0.1/lib/ruby/gems/1.8/gems/rails-1.2.4/lib/initializer.rb:543:in
`set_root_path!'<br>
&nbsp;&nbsp;&nbsp; from C:/testbed/ruby/jruby-1.0.1/lib/ruby/gems/1.8/gems/rails-1.2.4/lib/initializer.rb:509:in
`initialize'<br>
&nbsp;&nbsp;&nbsp; from ./script/../config/boot.rb:35:in `new'<br>
&nbsp;&nbsp;&nbsp; from ./script/../config/boot.rb:35:in `run'<br>
&nbsp;&nbsp;&nbsp; from ./script/../config/boot.rb:35<br>
&nbsp;&nbsp;&nbsp; from :1:in `require'<br>
&nbsp;&nbsp;&nbsp; from :1

and Rails 1.2.4 gives exactly the same error. This is
Ticket #9893. This actually happens because of JRUBY-1401.

The workaround is to use Rails 1.2.3. If you have already
installed the latest Rails plugin, then you can uninstall it using the command:

C:\testbed\ruby\jruby-1.0.1\bin&gt;gem uninstall rails<br>
Successfully uninstalled rails version 1.2.5<br>
Remove executables and scripts for<br>
'rails' in addition to the gem? [Yn] y<br>
Removing rails

And then install Rails 1.2.3 as:

gem install rails --include-dependencies --version 1.2.3 
--no-ri --no-rdoc<br>
Successfully installed rails-1.2.3<br>
Successfully installed activesupport-1.4.2<br>
Successfully installed activerecord-1.15.3<br>
Successfully installed actionpack-1.13.3<br>
Successfully installed actionmailer-1.3.3<br>
Successfully installed actionwebservice-1.2.3

Now create a new application as shown below:

jruby -S rails hello

And then create a controller as:

jruby script\generate controller say hello<br>
exists app/controllers/<br>
exists app/helpers/<br>
create app/views/say<br>
exists test/functional/<br>
create app/controllers/say_controller.rb<br>
create test/functional/say_controller_test.rb<br>
create app/helpers/say_helper.rb<br>
create app/views/say/hello.rhtml

Hope you find it useful and this bug is fixed in the next
version of Rails.

Please leave suggestions on other TOTD that you'd like to see. A complete
archive is available here.

Technorati:
totd
rubyonrails
jruby
windows

Related Topics >>