Forum: Ruby on Rails two instances of a controller?

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.
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2009-04-28 13:13
Hello,

I have written a guestbook and I'd like to use it twice in my
application. One public guestbook and one private guestbook. How can I
use the very same controller for two different guestbooks?

Thanks
40db9e75b3f5899258e3bdc0c9210154?d=identicon&s=25 Conrad Taylor (conradwt)
on 2009-04-28 13:32
(Received via mailing list)
I guess for the private guess book one  needs to login.  Then you'll
select the guess book for the logged in user.  In the public guess
book, one just enters their information and all entries can be saved
to a default user.  Well, that's all there is too it.

Good luck,

-Conrad

Sent from my iPhone

On Apr 28, 2009, at 4:13 AM, Heinz Strunk
<rails-mailing-list@andreas-s.net
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2009-04-28 13:48
Yes of course, that's how I wanna do it but the question was how to
'create' these two different guestbooks. I have one controller,
therefore I have one guestbook but how can I instantiate a second one
with the same controller but different entries etc.?

Conrad Taylor wrote:
> I guess for the private guess book one  needs to login.  Then you'll
> select the guess book for the logged in user.  In the public guess
> book, one just enters their information and all entries can be saved
> to a default user.  Well, that's all there is too it.
>
> Good luck,
>
> -Conrad
>
> Sent from my iPhone
>
> On Apr 28, 2009, at 4:13 AM, Heinz Strunk
> <rails-mailing-list@andreas-s.net
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-04-28 15:18
(Received via mailing list)
Data is not stored in a controller it is stored in the database, using a
model.  Is it that you want two tables with the two guestbooks in it?
That
does not sound like the best solution.

2009/4/28 Heinz Strunk <rails-mailing-list@andreas-s.net>
Fdb488647484e40f785dde7134afc6d1?d=identicon&s=25 Heinz Strunk (cojones)
on 2009-04-28 18:13
Not necessarily two tables. I read somewhere that it's possible to use
the same controller/model/whatever for various instances.

I don't know if you guys got me right... I've got a guestbook
controller/model/etc. and decide to have another guestbook. Copying the
controller/model/etc. and rename it to guestbook2 is very stupid that's
why I would like to know how I can use the same controller/model/etc.
and have 2 different guestbooks.

Colin Law wrote:
> Data is not stored in a controller it is stored in the database, using a
> model.  Is it that you want two tables with the two guestbooks in it?
> That
> does not sound like the best solution.
>
> 2009/4/28 Heinz Strunk <rails-mailing-list@andreas-s.net>
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-04-28 18:47
(Received via mailing list)
I still don't understand what you mean by two guestbooks.  If all you
want
is for different users to see different data then have one guestbook but
select the records based on the user.  If you want the second book to be
selected by a different url you could just pass a parameter to the
controller (in the url) to select the records.  There are probably
numerous
ways, it all depends what exactly you are trying to achieve.

2009/4/28 Heinz Strunk <rails-mailing-list@andreas-s.net>
5f94b9b346c2aa648a80bc259978e5bc?d=identicon&s=25 Colin Law (Guest)
on 2009-04-28 19:02
(Received via mailing list)
Or perhaps what you want is a table guest_books with one record for each
book.  Then the data is in a table guest_book_entries where GuestBook
has_many GuestBookEntries and GuestBookEntries belongs_to GuestBook.

2009/4/28 Colin Law <clanlaw@googlemail.com>
This topic is locked and can not be replied to.