Scaffold misuse?

Running ruby script/generate scaffold Product Admin

is a wonderful way to set up well, exactly what it says, a scaffold.

My problem is that I have several other tables that are linked,
through foreign keys, to the Product table. Say an “authors” table.
Now when I go enter a new product, a book, I want the application to
provide a drop down list of authors generated from the records in the
authors table and let me choose an author when I enter my other book
details. I also want the application to allow me to administer the
authors table to CRUD authors.

I know that I can start off as above and do lots of copy/past and
search/replace of/in the MVC tree to provide CRUD for authors and list
them in the new product view, but I’d rather use any functionality
that Rails might have to auto generate these.

Can/should I run ruby script/generate scaffold Admin for each
entity in my schema?

Bealach

You want ruby script/generate model <modelname: like “author”>.

What this will do: create the basic code that will link to the
appropriate MySQL table.

What this won’t do: create new controller code, and a bunch of new view
pages.

I think this is what you want.

-Adam

Hi Adam,

Thanks very much for your comments. I obviously have not quite
understood
Rails yet. Why does it not generate the contorller/view code? It does
such a
nice job of setting things up for the admin, why not provide the same
framework for each model?

Bealach

Can/should I run ruby script/generate scaffold Admin for each
entity in my schema?

In fact, this is exactly what you should do. :slight_smile:

So:
ruby script/generate scaffold Product Admin

My problem is that I have several other tables that are linked,
through foreign keys, to the Product table. Say an “authors” table.

Now if Bealach’s scaffold looks like mine, author_id is not a recognized
field; I have no way to edit author_id in existing records and no way to
add it to new records.

So I try:
ruby script/generate scaffold Author Admin

which replaces the preceding scaffold (Product) with an entirely new one
(Author), but does not appear to combine or link the models.

And it won’t.

Here’s what I do (it won’t work for depot) but it will work for your own
app)

ruby script/generate scaffold Product admin/product
ruby script/generate scaffold Author admin/author

Then make a route that maps /admin/ to a specific controller

map.connect ‘/admin’, :controller=>"/admin/proudct", :action=>“index”

Then it’s just a matter of making a menu that links things around using
link_to or named routes.

Hi guys,

On 4/5/06, Justin S. [email protected] wrote:

//>through foreign keys, to the Product table. Say an “authors” table.
//
//Now if Bealach’s scaffold looks like mine, author_id is not a recognized
//field; I have no way to edit author_id in existing records and no way to
//add it to new records.

On this point I was helped by Charlie B.'s answer to an earlier post
of
mine (almost identical to yours Justin). So I quote,

“You can always edit the .rhtml files to include any fields that are
not
showing. By default the primary fields and foreign key aren’t shown
when
you scaffold a table.”

//

//So I try:
//ruby script/generate scaffold Author Admin
//
//which replaces the preceding scaffold (Product) with an entirely new one
//(Author), but does not appear to combine or link the models.
//

Correct, and this is where I was hoping I could be lazy and find a way
to
let Rails produce lots of nice code for me. Alas, I have not found a way
and
have ended up with the following solution:

$> ruby script/generate scaffold Product Admin
to get my “main” entry point
edited the the _form.rhtml file to add the missing author_id field for
user
entry
$>ruby script/generate controller Author list new create destroy
to get a bunch of very basic files like author_controller.rb that has
all my
method with empty bodies
edited the rest by hand :expressionless:

Of course, you have start writing code at some stage, I was just hoping
I
could get more for free :slight_smile:

Bealach

Bealach Na Bo wrote:

Hi Adam,

Thanks very much for your comments. I obviously have not quite
understood
Rails yet. Why does it not generate the contorller/view code? It does
such a
nice job of setting things up for the admin, why not provide the same
framework for each model?

Bealach

Now I realize I’ve misread your post. Very sorry.

Can/should I run ruby script/generate scaffold Admin for each
entity in my schema?

In fact, this is exactly what you should do. :slight_smile:

-Adam

:slight_smile: Technology rocks, doesn’t it?

Hi Brian,

Your comments are very welcome, but I only found them by chance since I
only read the stuff I get in gmail from lists.rubyonrails.org, that’s
why, I seem to be totally ignoring what you point out in my previous
posting…sorry :slight_smile:
Bealach

Brian H. wrote:

And it won’t.

Here’s what I do (it won’t work for depot) but it will work for your own
app)

ruby script/generate scaffold Product admin/product
ruby script/generate scaffold Author admin/author

Then make a route that maps /admin/ to a specific controller

map.connect ‘/admin’, :controller=>“/admin/proudct”, :action=>“index”

Then it’s just a matter of making a menu that links things around using
link_to or named routes.

Bealach Na Bo wrote:

OK Brian’s way of doing it works nicely, but my scaffold.css is somehow
ignored by all
the views even though every layout has the line

<%= stylesheet_link_tag ‘scaffold’ %>

I thought scaffold.css in /public/stylesheets would be loaded
by all views…

View the source for your rendered html. What is the stylesheet link?

Ray

OK Brian’s way of doing it works nicely, but my scaffold.css is somehow
ignored by all
the views even though every layout has the line

<%= stylesheet_link_tag ‘scaffold’ %>

I thought scaffold.css in /public/stylesheets would be loaded
by
all views…
Any ideas?

Bealach

On 4/6/06, Ray B. [email protected] wrote:

View the source for your rendered html. What is the stylesheet link?

Ray

Hi Ray,

There just ain’t any! It’s very odd.

For each model, I have a directory under
app/views/admin
where things like
list.rhtml new.rhtml show.rhtml
live
corresponding to each of the models, I have a layout in
app/views/layouts

In every layout, I have
<%= stylesheet_link_tag ‘scaffold’ %>

finally, I have
public/stylesheets/scaffold.css

which is not loaded in to any of the rendered views!

Bealach

You might want to look into
http://wiki.rubyonrails.org/rails/pages/Scaffolding+Extensions+Plugin

On 4/7/06, David M. [email protected] wrote:

http://lists.rubyonrails.org/mailman/listinfo/rails

Thanks David! It looks VERY interesting. I’ll have to dig into it…

Bealach