Forum: Ruby on Rails combining two models in one controller/view "set"

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
31ae911dd0fe0ee0b81519d6d2627886?d=identicon&s=25 Gravy Face (gravyface)
on 2006-03-28 20:42
(Received via mailing list)
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
6dab365a82517fb694650a57ee88e4a4?d=identicon&s=25 joey__ (Guest)
on 2006-03-28 22:13
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 Development with rails.

Joey__
[1] http://en.wikipedia.org/wiki/Scaffolding
31ae911dd0fe0ee0b81519d6d2627886?d=identicon&s=25 Gravy Face (gravyface)
on 2006-03-28 23:38
(Received via mailing list)
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.  :)
58c44a4a506d878f9a112f1d7b7cb87e?d=identicon&s=25 Jeremy Evans (Guest)
on 2006-03-29 01:24
(Received via mailing list)
On 3/28/06, GravyFace <gravyface@gmail.com> 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:
http://wiki.rubyonrails.com/rails/pages/Scaffoldin....
31ae911dd0fe0ee0b81519d6d2627886?d=identicon&s=25 Gravy Face (gravyface)
on 2006-03-29 01:36
(Received via mailing list)
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?
:)
24e30ea2f4bfda89a9a915dd18247d05?d=identicon&s=25 Jeremy Huffman (Guest)
on 2006-03-29 04:08
(Received via mailing list)
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 <gravyface@gmail.com> wrote:
> > > relationships into account?
> > http://lists.rubyonrails.org/mailman/listinfo/rails
> >
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Jeremy Huffman
http://www.jeremyhuffman.com
This topic is locked and can not be replied to.