views:

47

answers:

2

I created a controller and a model. The controller is called "Admin" and the model is called "Album". I edited database.yml with proper info and did the rake db:migrate command which didn't return any errors and did migrate the db inside schema.rb. Inside the controller I wrote:

class AdminController < ApplicationController

  scaffold :album

end

Next I started my server and went to http://localhost:3000/admin but instead of seeing the typical CRUD page I get the following error:

app/controllers/admin_controller.rb:3

Request

Parameters: 

None

Show session dump

--- 
flash: !map:ActionController::Flash::FlashHash

{}

Response

Headers: 

{"cookie"=>[],
 "Cache-Control"=>"no-cache"}

Any idea why?

A: 

Hm,

Normally you would have a controller and a model called Admin and the same thing would be about Album,

Take a look at this quick screen cast how a blog is done using scaffolding;

Creating a web-blog

Adnan
+1  A: 

That syntax for scaffolding has been deprecated for quite some time. Nowadays, rails (versions 2.x) use the following method to scaffold a resource:

script/generate scaffold Album title:string date:date ...

That generates the scaffolding views (in app/views), the controller (app/controllers), standard tests (in test/) and, crucially, the required routes to make scaffolding work.

I believe the rails dev team took away the old syntax ("scaffold :resource") because no real application would ever leave a scaffold untouched, ie. you will always need some kind of customization. With the new syntax you can leave it untouched, but it is also much easier to customize.

If you really need your controller to be named admins, you can change the file config/routes.rb after generating the scaffolding. It makes no sense, though: Why should the URI to create a new album be called "/admins/new"?

If you are trying to create an admin area for an image album app, you are probably looking for namespaces (so you can have multiple different resources, controllers and views inside the "admin" namespace). To create an album resource within the admin namespace, write:

script/generate scaffold Admin/Album title:string date:date

In that case, your controller will be accessible as http://host/admin/albums.

sigvei