Combining two models in one controller/view "set"

I’m going to take another stab at this question (my first one received
no replies):

I have two models:

Author
has_many: books

Book
has_one: author

I have two tables:

authors
id

books
id
author_id

I let the scaffolding fly and it created the CRUD goodness for each
model, as expected.

However, I want to have only one view/controller “set” for both
models; when I refer to “set”, I mean having a generic controller
called Library with methods for create, edit, show, destroy, and list,
but these methods would access and manipulate this combined data set
of authors and their books from both models.

After sifting through both the controllers and views and adding
those relationships (described above) is there any way to:

a) run the scaffolding again so that it will take these new
relationships into account?
b) if not, how should I proceed?

I am a complete Ruby/RoR/MVC luddite and am open to any suggestions
here.

Thanks

gravy face wrote:

I’m going to take another stab at this question (my first one received
no replies):

I have two models:

Author
has_many: books

Book
has_one: author

I have two tables:

authors
id

books
id
author_id

I let the scaffolding fly and it created the CRUD goodness for each
model, as expected.

However, I want to have only one view/controller “set” for both
models; when I refer to “set”, I mean having a generic controller
called Library with methods for create, edit, show, destroy, and list,
but these methods would access and manipulate this combined data set
of authors and their books from both models.

After sifting through both the controllers and views and adding
those relationships (described above) is there any way to:

a) run the scaffolding again so that it will take these new
relationships into account?
b) if not, how should I proceed?

I am a complete Ruby/RoR/MVC luddite and am open to any suggestions
here.

Thanks
Scaffolding[1]:
Scaffolding is a temporary framework used to support people and material
in the construction or repair of buildings and other large structures.

You cannot do this with scaffolding, you need to write this yourself. I
suggest you buy or read Agile Web D. with rails.

Joey__
[1] Scaffolding - Wikipedia

As for the book, I have it, I haven’t had a chance to read it yet
(only skimmed through it). And as for the answer, I was hoping this
was a common “pattern” that somebody has stumbled across before and
perhaps blogged or wiki’ed it; Google came up with nothing although my
terms are pretty ambiguous.

+1 for the burn – but at least I got a response this time. :slight_smile:

On 3/28/06, GravyFace [email protected] wrote:

After sifting through both the controllers and views and adding
those relationships (described above) is there any way to:

a) run the scaffolding again so that it will take these new
relationships into account?
b) if not, how should I proceed?

I am a complete Ruby/RoR/MVC luddite and am open to any suggestions here.

It might not be completely what you want, but you could look into the
Scaffolding Extensions Plugin:
Peak Obsession.

Perfect, thanks man. I’m not planning on leaning on the scaffolding
crutch forever, but c’mon, who didn’t switch to Rails because of it?
:slight_smile:

The sooner you ditch scaffold the sooner you will grok rails. I swear
that feature has done as much harm as good.

On 3/28/06, GravyFace [email protected] wrote:

relationships into account?
http://lists.rubyonrails.org/mailman/listinfo/rails


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Jeremy H.