Multiple views of the same model

Hi,

How can I implement two different views on the same model? My model
has 30 attributes. The First view should display 1-12 and the second
view the rest of them.

In my case I am dealing with two medical anamneses with different
topics. My idea was to generate a model called anamnesis with every
field name of the two topics. This model should be split into two views.

Regards
Jonas

2009/10/5 Jonas L. [email protected]:

Hi,

How can I implement two different views on the same model? My model
has 30 attributes. The First view should display 1-12 and the second
view the rest of them.

In my case I am dealing with two medical anamneses with different
topics. My idea was to generate a model called anamnesis with every
field name of the two topics. This model should be split into two views.

You could use a parameter in the url for the show action to indicate
which view you want, then in the show action test the parameter and
render the appropriate view.
You could use a separate action in the controller.
You could use a separate controller for the second view.
If one view is showing some attributes and another only the rest (not
clear from your post whether the second view shows all of them or
not), then consider whether it should be a separate model.

Colin

Have a look at Florian Hanke’s Representer plugin:

It allows you to have ‘object oriented’ views, maybe it suits your
needs…

Andi

Thanks for the suggestions. I will try it.

Am 05.10.2009 um 10:46 schrieb Andi S.:

Jonas L. wrote:

Hi,

How can I implement two different views on the same model? My model
has 30 attributes. The First view should display 1-12 and the second
view the rest of them.

In my case I am dealing with two medical anamneses with different
topics. My idea was to generate a model called anamnesis with every
field name of the two topics. This model should be split into two views.

It sounds like you’re reinventing single-table inheritance here. Why
not just use Rails’ single-table inheritance features?

Better yet, don’t try to put two classes in one table. Single-table
inheritance works, but is problematic since it doesn’t really fit the
relational model. Start with it, but consider refactoring to
multiple-table inheritance.

Regards
Jonas

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]