I was originally using instant rails, and decided to try installing ruby, rails, and mysql on my own. No problem with the install. I used gem install rails --include-dependencies, and got no errors. The problem seems to be with defining the scaffold method. I had no problems with this in Instant Rails, and i’m guessing this has something to do with Rails 2.0. Would the RoR gurus please lend a hand, and guide me to the light?
thanks,
Jason
NoMethodError in AdminController#index
undefined method `scaffold’ for AdminController:Class
Yep, dynamic scaffolding has been moved out to a plugin in Rails 2.0.
Your options are:
1) Switch to rails 1.2.6. This will be the easiest route if you're
still learning rails using AWDWR 2nd ed.
2) Install the scaffolding plugin with:
script/plugin install scaffolding
Option 1 means you are continuing to tread on the same turf expected
by the book, Option 2 is but on step towards adapting your knowledge,
and the books, to Rails 2.0.
I too had the AWDwR book 2nd Edition, P3.0 printing (use the P2.0
errata says Dave).
I installed the scaffolding plugin. That step alone, didn't help,
although it may have been best to delete the depot folder and start
again. But that plugin may have been a different type of scaffolding.
I went back to rails version 1.2.5, that was installed when I first
set up Ruby on Linix Fedora 7. I used the commands from a later post
(Jan 1, by Jos Achten, step 3). In fact I had 1.2.5, and 2.0.2
installed and it asked me which I wanted to uninstall. In the end I
uninstalled both and asked for "--version 1.2.5 --include-
dependencies" and that did it. Then I had to delete the depot folder
and restart from the beginning of that chapter. Everything worked as
on pages 68 onward. Frankly, I'm impressed that it generated so much
automatically.
Thank you for asking the questions, and thank you for all the replies!
I just ran into the same issue and had it resolved in no time flat
thanks to you!
Summary:
1. I had installed Rails according to the Windows recommendation in
the book
2. When I ran into the problem, I googled the error message, found
this error message, and did the following:
3. typed "gem uninstall rails" at the rails command line
4. typed "gem install rails --version 1.2.6 --include-dependencies"
at the rails command line
5. delete or rename the original depot folder
6. do the following to quickly get back to where you were when the
error hit you:
D:\Rails\rails_apps\work>rails depot
cd depot
D:\Rails\rails_apps\work\depot>ruby script/generate model product
edit D:\Rails\rails_apps\work\depot\db\migrate\001_create_products.rb
add
t.column :title, :string
t.column :text, :text
t.column :image_url, :string
rake db:migrate
ruby script/generate controller admin
edit D:\Rails\rails_apps\work\depot\app\controllers
\admin_controller.rb
add
scaffold :product
(change D:\Rails to where you installed rails, obviously)
Just a quick correction to the last entry. When editing the migration
for the products model, the line 't.column :text, :text' should be
't.column :description, :text'. My validation kept failing until I
realized that the 'description' column had been incorrectly named as
'text'.
If you're following the AWDWR book using Rails 2 you will hit other
problems - for example when it talks about pagination that has been
removed from Rails 2 so it won't work as expected. While running through
the Depot for learning I'd stick with 1.2.6 and then start develping on
1.2.6 so you can rely on the book. Only make the change to 2.0 when
you're comfortable with the basics.
I originally got the <b>undefined method `scaffold' for
AdminController:Class</b>
then after installing pagination I got <b>undefined method `paginate'
for #<AdminController:...</b>
How I got around was this:
1) check all installed gems on your machine
<b>gem list --local </b>
check the rails versions installed (in my case, this was 2.0.2, 1.2.6,
1.2.5, 1.2.3)
2) uninstall version 2.0.2, using this command:
<b>sudo gem uninstall -v=2.0.2 rails</b>
I admit, I'm a Rails noob and have been following the instructions in
AWDwR edition *3*, they haven't mentioned lack of support for this, so
you kind of get stuck on page 76. Is it worth rolling back my version
of rails do you think, or is scaffolding something I can live/learn
without ...
Is there any place where it is summarized the changes to make to
Awdwr's depot exercise if we decide to use RoR 2.0?
It doesn't make sens to me to learn an old technology when I'm not
gonna stick with it anyways...