Old Scaffold Problem on Lynda Ruby on Rails Essential Training
There are a number of people following lynda.com’s Ruby on Rails Essential Training tutorial and running into issues since some of the information in the tutorial is outdated. The method scaffold was removed from Rails 2.0. You can still create scaffolds but must do so by generating the scaffold files explicitly.
If you see NoMethodError in your logs
Processing ApplicationController#index (for ::1 at 2010-01-11 21:04:25) [GET] NoMethodError (undefined method `scaffold' for AdminController:Class): app/controllers/admin_controller.rb:2 /usr/local/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/local/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /usr/local/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /usr/local/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `each' /usr/local/lib/ruby/1.8/webrick/server.rb:92:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/local/lib/ruby/1.8/webrick/server.rb:82:in `start'
View the db/schema.rb file to get clues on how to generate Scaffold
Assuming you are following the Ruby on Rails Essential Training video Ch. 5. Setting up a Database | Scaffold: Magic CRUD Screencast, you can get some clues as to what Table and fields needs to be created with the script/generate command. Notice below the db/schema.rb file contains the following table albums and fields title, artist, release_date and genre. Also notice their corresponding field types.
ActiveRecord::Schema.define(:version => 0) do create_table "albums", :force => true do |t| t.string "title", :null => false t.string "artist", :null => false t.datetime "release_date", :null => false t.string "genre", :limit => 50, :null => false end end
Generate the Scaffold for Album model
Execute the following command:
script/generate scaffold Album title:string artist:string release_date:datetime genre:string
Then restart your server and hit http://localhost:3000/albums instead of http://localhost:3000:/admin
Old Scaffold Problem on Lynda Ruby on Rails Essential Training,
2 Comments to “Old Scaffold Problem on Lynda Ruby on Rails Essential Training”