Starting Ruby on Rails 2 with Netbeans and AWDWR book

After some break, I got back to Rails land. The return is not as smooth as I hoped: since Rails 2.0, many things work differently and quite a few steps learned from “The Book” do not work any more. The issues are more often than not quite easy to fix, but there is quite a few of them.

All the following is related to NetbeansRuby build 6327 from Jan 26th with JRuby 1.1RC1

After installing NetbeansRuby and updating the Gems (Tools->Ruby Gems), the attempt to generate Rails application fails:

/Users/miro/Applications/ `report_activate_error': Could not find RubyGem activeresource (= 2.0.2) (Gem::LoadError)

        from /Users/miro/Applications/ `activate'
        from /Users/miro/Applications/ `activate'
        from /Users/miro/Applications/ `each'
        from /Users/miro/Applications/ `activate'
        from /Users/miro/Applications/ `active_gem_with_options'
        from /Users/miro/Applications/ `gem'
        from /Users/miro/Applications/

Looks like the gem updater somehow missed activeresource – maybe a problem with dependencies ?To fix this, manually install activeresource 2.0.2 – Tools -> Ruby Gems, New Gems, search for resource, install. This is list of the installed gems:

  • actionmailer (2.0.2, 1.3.5)
  • actionpack (2.0.2, 1.13.5)
  • actionwebservice (1.2.6, 1.2.5)
  • activerecord (2.0.2, 1.15.5)
  • activerecord-jdbc-adapter (0.7.2, 0.7)
  • activeresource (2.0.2)
  • activesupport (2.0.2, 1.4.4)
  • jruby-openssl (0.1.1)
  • rails (2.0.2, 1.2.5)
  • rake (0.8.1, 0.7.3)
  • rspec (1.1.3, 1.1.1)
  • sources (0.0.1)

By default, the Rails 2 selects Sqlite3 database. This is great choice if you use C-Ruby, but not so great for JRuby – see this post. After few frustrated attempts to find workaround, I decided to go with Ruby 1.8.6, updated (again) the Gems in system installation (the first updated upgraded JRuby gems) and decided to try out the Depot sample – just have something that works, rather than fighting with issues of both Rails 2 and my own bugs. To keep with the book, I stayed with MySQL (quietly running in VMWare virtual machine).

By the book I have generated Product model and Admin controller, but instead of seeing familiar screen, Rails responded with error:

Routing Error

No route matches "/admin" with {:method=>:get}

This can be fixed by addingmap.connect ‘:controller/:action’to routes.rb, but this is probably bad idea because it goes against REST design principles which Rails 2 tries to promote. But to go ahead with the example, I hacked it 🙂 and added scaffolding. Next error I got was:

 NoMethodError in AdminController#index

undefined method `scaffold' for AdminController:Class

RAILS_ROOT: /Users/miro/Projects/RAILS2/Depot
Application Trace | Framework Trace | Full Trace

/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in `load_without_new_constant_marking'
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:203:in `load_file'
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in'
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:202:in `load_file'
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:94:in `require_or_load'
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:248:in `load_missing_constant'
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:453:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/dependencies.rb:465:in `const_missing'
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/inflector.rb:257:in `constantize'
/Library/Ruby/Gems/1.8/gems/activesupport-2.0.2/lib/active_support/core_ext/string/inflections.rb:148:in `constantize'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/routing.rb:1426:in `recognize'

Scaffolding is one of the parts removed in Rails 2. :-(. I tried to install ‘scaffolding’, which led to another error:

NoMethodError in AdminController#index

undefined method `paginate' for #<AdminController:0x2cafe34>

RAILS_ROOT: /Users/miro/Projects/RAILS2/Depot
Application Trace | Framework Trace | Full Trace

vendor/plugins/scaffolding/lib/scaffolding.rb:107:in `list'
vendor/plugins/scaffolding/lib/scaffolding.rb:95:in `index'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb:1158:in `perform_action_without_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters'

Based on this post, I installed classic_pagination, which resulted in another error when trying to enter new Product

 ActionController::InvalidAuthenticityToken in AdminController#create


RAILS_ROOT: /Users/miro/Projects/RAILS2/Depot
Application Trace | Framework Trace | Full Trace

/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/request_forgery_protection.rb:79:in `verify_authenticity_token'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:469:in `send!'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:469:in `call'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:441:in `run'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:716:in `run_before_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:695:in `call_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/filters.rb:689:in `perform_action_without_benchmark'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue'
/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching'

I backtracked, and tried to go with generated scaffold, rather with dynamic. The generated views were named edit.html.erb, rather than edit.rhtml and the generator did not allow to enter controller (second argument). This lead to error


Template is missing

Missing template admin/index.html.erb in view path /Users/miro/Projects/RAILS2/Depot/app/views

At this point I gave up and decided to:

  • read the Rails 2.0 documentation (after everything else failed, read the manual …)
  • reconsider using AWDWR as the guide – obviously, it needs to be updated to be useful with Rails 2. If you purchased the PDF from Pargmatic Programmers, there is an update available on their website, but it is not an update for Rails 2 …

I was not the only person to try AWDWR with Rails 2. The best resource I found was Ruby Plus website with series of screencasts, starting with this. The author – Bala Paranj did great job in putting together very useful collection of Rails screencasts. If you want to use the AWDWR with Rails 2.0, listen to them first – unless you are very experienced Rails developer.


2 Responses to Starting Ruby on Rails 2 with Netbeans and AWDWR book

  1. AJ says:

    I’m curious as to why you would want to use an out dated book with a new version of rails? There’s going to be things in the book that don’t apply anymore. I would go an install the versions that they are using from the book if you are just getting started. If you are a “very experienced” Rails developer, as you put it, I doubt that they would be using this book still. I have went through the book (1.5 years ago) and still reference from it time to time, but I would not suggest someone wanting to learn Rails use Rails 2.0 and this book. I’ve heard great things about the book, The Rails Way,, which does talk about Rails 2.0, whereas AWDWR doesn’t. Just my .2 cents.


  2. Miro says:

    I do not know about any Rails 2 book so this was an attempt to refresh what I have forgotten during 5 months doing exclusively Java a no Ruby/Rails. Besides that’s the book I have :-).

    The Rails Way is what I am reading now but from quick browse it is still based on Rails 1.2 – e.g. it is mentioning index.rhtml, not index.html.erb.

    But it looks like the book goes very deep and is probably the “second book”

%d bloggers like this: