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 Latza <to.the.matrix-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> > 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: http://github.com/floere/representer It allows you to have ''object oriented'' views, maybe it suits your needs... Andi On Oct 5, 10:19 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2009/10/5 Jonas Latza <to.the.mat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > > > 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
Thanks for the suggestions. I will try it. Am 05.10.2009 um 10:46 schrieb Andi Schacke:> > Have a look at Florian Hanke''s Representer plugin: > > http://github.com/floere/representer > > It allows you to have ''object oriented'' views, maybe it suits your > needs... > > Andi > > On Oct 5, 10:19 am, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: >> 2009/10/5 Jonas Latza <to.the.mat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: >> >> >> >>> 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 > >
Jonas Latza 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 > JonasBest, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/.