View sharing between controllers?


#1

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.


#2

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.