Forum: Ruby on Rails View sharing between controllers?

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.
Justin Streufert (Guest)
on 2006-03-29 08:34
(Received via mailing list)
Good evening all....

My first Rails project is flourishing, thanks in no small part to
good advice I received from members of this mailing list (thanks!).
However, I've run into an interesting spot on which I'd really
appreciate your advice.

My app's main controller currently has about a dozen views,
presenting various information about the models. This controller is
only available to registered users of the site and works only on
objects owned by the current user.

I now want to add a "public-facing" interface to the SAME models,
giving all site visitors read-only access to the users' data. My
instinct is to build another controller for this purpose. My problem
is that I want to use very similar view templates to display the
data, and DRY says I shouldn't just copy and paste the controller
methods and .rhtml files from the private controller to the public
one (and I agree!!)

My question is: What is the best way to share these very similar
views between two controllers? Or, should I give up on the idea of
using two controllers and apply selective authentication to the
single controller?

I'd really appreciate any feedback you folks might have.

Thanks much!!
Justin

P.S. Congratulations to the developers on the beautiful 1.1 release.
My upgrade, for one, went flawlessly, and the new features will be of
much use.
jack (Guest)
on 2006-03-29 15:04
Couple of ways -
1) create a new separate class (ie Common)
2) create it as a partial


Justin Streufert wrote:
> Good evening all....
>
> My first Rails project is flourishing, thanks in no small part to
> good advice I received from members of this mailing list (thanks!).
> However, I've run into an interesting spot on which I'd really
> appreciate your advice.
>
> My app's main controller currently has about a dozen views,
> presenting various information about the models. This controller is
> only available to registered users of the site and works only on
> objects owned by the current user.
>
> I now want to add a "public-facing" interface to the SAME models,
> giving all site visitors read-only access to the users' data. My
> instinct is to build another controller for this purpose. My problem
> is that I want to use very similar view templates to display the
> data, and DRY says I shouldn't just copy and paste the controller
> methods and .rhtml files from the private controller to the public
> one (and I agree!!)
>
> My question is: What is the best way to share these very similar
> views between two controllers? Or, should I give up on the idea of
> using two controllers and apply selective authentication to the
> single controller?
>
> I'd really appreciate any feedback you folks might have.
>
> Thanks much!!
> Justin
>
> P.S. Congratulations to the developers on the beautiful 1.1 release.
> My upgrade, for one, went flawlessly, and the new features will be of
> much use.
This topic is locked and can not be replied to.