scaffold :product missing in Rails 2.0.2 version of depot tutorial?

I am getting an error when I try to run the code for the depot application (page 67 in the Agile Web Development on Rails book, 2nd edition). I built the complete depot app with Rails 1.2.6, and all worked well. I then updated to Gem 1.0.1 and RoR 2.0.2, and attempted to repeat the tutorial, and got this strange behavior.

I used "rails depot --database=mysql" because I have not installed sqlite3 I followed the instructions on pages 59 through 67 carefully, and checked that the products table was created correctly. I then added the scaffold line in admin_controller.rb (see below)

# admin_controller.rb (code from example) class AdminController < ApplicationController   scaffold :product end

and then, started WEBrick, went to the browser and typed "http:// localhost:3000/admin/" and got the following dump in the browser window.

NoMethodError in AdminController#index

==> undefined method `scaffold' for AdminController:Class <==

RAILS_ROOT: /home/kenb/2nd-ed-rails-book/projects/depot Application Trace | Framework Trace | Full Trace

app/controllers/admin_controller.rb:2

/usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:203:in `load_without_new_constant_marking' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:203:in `load_file' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:342:in `new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:202:in `load_file' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:94:in `require_or_load' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:248:in `load_missing_constant' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:453:in `const_missing' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:465:in `const_missing' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ inflector.rb:257:in `constantize' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ core_ext/string/inflections.rb:148:in `constantize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ routing.rb:1426:in `recognize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:170:in `handle_request' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:115:in `dispatch' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:126:in `dispatch_cgi' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:9:in `dispatch' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:112:in `handle_dispatch' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:78:in `service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/lib/ruby/1.8/webrick/server.rb:162:in `start' /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/lib/ruby/1.8/webrick/server.rb:92:in `each' /usr/lib/ruby/1.8/webrick/server.rb:92:in `start' /usr/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/lib/ruby/1.8/webrick/server.rb:82:in `start' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:62:in `dispatch' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/ webrick.rb:66 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:496:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:342:in `new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:496:in `require' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' script/server:3

app/controllers/admin_controller.rb:2 /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:203:in `load_without_new_constant_marking' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:203:in `load_file' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:342:in `new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:202:in `load_file' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:94:in `require_or_load' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:248:in `load_missing_constant' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:453:in `const_missing' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:465:in `const_missing' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ inflector.rb:257:in `constantize' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ core_ext/string/inflections.rb:148:in `constantize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ routing.rb:1426:in `recognize' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:170:in `handle_request' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:115:in `dispatch' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:126:in `dispatch_cgi' /usr/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ dispatcher.rb:9:in `dispatch' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:112:in `handle_dispatch' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:78:in `service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/lib/ruby/1.8/webrick/server.rb:162:in `start' /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/lib/ruby/1.8/webrick/server.rb:92:in `each' /usr/lib/ruby/1.8/webrick/server.rb:92:in `start' /usr/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/lib/ruby/1.8/webrick/server.rb:82:in `start' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:62:in `dispatch' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/servers/ webrick.rb:66 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:496:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:342:in `new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:496:in `require' /usr/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39 /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' script/server:3

Request

Parameters:

None

Show session dump

The method scaffold has been removed from Rails 2.0

I have detailed this in a post: Leonardo Borges | rails 20 scaffold

There you will find the solution.

Hope this helps.

Dynamic scaffolding is no longer available in rails 2. You would need to use the scaffolding generator to generate a static scaffold.

-Bill

explainer wrote:

I’m just really surprised this keeps coming up, as it’s been answered before.

In order to use the Agile Web Dev book, you need to use an older version of Rails until they update the book.

gem install -v=1.2.3 rails

Then recreate the depot app using the older Rails version

rails 1.2.3 depot

(the 1.2.3 tells the generator which one to use. By default it uses the latest Rails gems.)

Once you finish the depot app in the book, you can move towards learning Rails 2.0.

An attempt to upgrade to 2.0.2 while doing the depot tutorial is really broken. The database is changed, scaffolding doesn't work, pagination is broken, the 'authorize' method is missing.

In short, the whole d**n demo is broken. I think I will bag Rails 2.0.2 until I at least get through the book.

This sucks. I expect at least some graceful deprecation when features change, not a complete train-wreck.

I am having the same problem as Explainer.

Checkout www.rubyplus.com He has the Depot app being built in Rails 2.0 fashion.

Dynamic scaffolding is no longer in rails 2.0. You will need to generate the scaffold.

-Bill

mel ram wrote:

I just installed the ActiveScaffold plugin: http://activescaffold.com/

It seems to substantially replace the original scaffold method.

Thanks, I just watched Bala's video on the proper Rails 2.0 way to scaffold the depot app.

I've had the same problem as well. As a complete noob to Rails, I'd like to be learning the current version of Rails rather than the deprecated version, but it's a bit disheartening to find that almost the first thing the Agile book has you do no longer works.

I've seen messages elsewhere to the effect that 'if you had been following the blogs, you'd have known that dynamic scaffolding was going away'. But the point is I'm new. I'm not following the blogs. I'm trying to find my footing.

Please note also that despite numerous pointers on www.rubyonrails.org to the Agile book, there's nothing that suggests that it is incompatible with the current version of Rails.

You’ve probably heard this before, but the agile book is perfect for a beginner as long as you use the older version of Rails used in the book. The changes in the current version of Rails are not that different.

The fact is that it takes a LONG time to write a book and Rails moves fast. In a few months, what you know won’t matter much because things will have changed. Learn Rails 1.2.3 and get the Depot app done, and then go to peepcode.com and get the “What’s new in Rails 2.0” book to get caught up. :slight_smile:

gem install rails --version=1.2.3

rails 1.2.3 depot

cd depot

Now you are using Rails 1.2.3 for the depot app

ruby script/generate scaffold Product admin

And there you go!

Brian Hogan wrote:

gem install rails --version=1.2.3

If only it were that easy. Here's what I find on April 27 2008:

matt@blacksmith:$ gem list rails --remote

*** REMOTE GEMS ***

Bulk updating Gem source index for: http://gems.rubyonrails.org/ rails (2.0.2.9216, 2.0.2.9129, 2.0.2.9126, 2.0.2.9122, 2.0.2.9097, 2.0.2) rails-app-installer (0.2.0) ...

I'm sure there's a Gem repository somewhere that still includes version 1.2.3 (or 1.2.5) but where?

Your gem source is wrong.

gem sources -r gems.rubyonrails.org

Ryan Bigg wrote:

Your gem source is wrong.

agreed.

gem sources -r gems.rubyonrails.org

huh? Is that a typo? See previous post: that's what I had. Rails 1.2.x is to be found at rubyforge, not rubyonrails.

Near as I can tell, a bad/missing rake was part of the problem:

matt@blacksmith:~$ rake -v rake aborted! No Rakefile found (looking for: rakefile, Rakefile, rakefile.rb, Rakefile.rb) /usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:2143:in `raw_load_rakefile'

Once that got fixed, things began to look better:

matt@blacksmith:~$ rake --version rake, version 0.8.1

matt@blacksmith:~$ gem list rails --remote *** REMOTE GEMS *** Bulk updating Gem source index for: http://gems.rubyforge.org/ Bulk updating Gem source index for: http://gems.rubyonrails.org/ rails (2.0.2.9216, 2.0.2.9129, 2.0.2.9126, 2.0.2.9122, 2.0.2.9097, 2.0.2, 2.0.1, 2.0.0, 1.2.6, 1.2.5, 1.2.4, 1.2.3, 1.2.2, 1.2.1, 1.2.0, 1.1.6, 1.1.5, 1.1.4, 1.1.3, 1.1.2, 1.1.1, 1.1.0, 1.0.0, 0.14.4, 0.14.3, 0.14.2, 0.14.1, 0.13.1, 0.13.0, 0.12.1, 0.12.0, 0.11.1, 0.11.0, 0.10.1, 0.10.0, 0.9.5, 0.9.4.1, 0.9.4, 0.9.3, 0.9.2, 0.9.1, 0.9.0, 0.8.5, 0.8.0, 0.7.0, 0.6.5, 0.6.0)

However, gem is still being deliberately difficult:

matt@blacksmith:~$ sudo gem install rails -v=1.2.6 Bulk updating Gem source index for: http://gems.rubyonrails.org/ ERROR: could not find rails locally or in a repository

Even though gem will happily list both repository indices, it won't install 1.2.x unless specifically told to use rubyforge:

matt@blacksmith:~$ sudo gem install rails -v=1.2.6 --source=http://gems.rubyforge.org/ Bulk updating Gem source index for: http://gems.rubyforge.org/ Successfully installed activesupport-1.4.4 Successfully installed activerecord-1.15.6 ...

Which is fine by me. As long as I can get a clean copy of old Rails to use with a newly-inherited Rails app, I'm a happy codr. :wink:

Dammit did I post in the wrong thread? Seems like it!