Abstract rails models

Hi, I need some advises on rails best practices when it comes to abstract/concrete models/classes in Rails. This is what I want to accomplish: A abstract type of page that holds base functionality like name, memberships, templates and other possible generic stuff. Then I want to have subclasses like ProjektPage or CoursePage and these classes should of course have it's own implementations and attributes. The only rails way I found on how to do this is with STI, however that is not a solution here because the subclasses of page will likely be very widespread.

So what are the best technique for handling this problem? I tried polymorphic association on the page class and then used a has_one :page on each subclass of page. However this is very hard to maintain and hard in new/edit forms. I am desperate for an answer!:slight_smile:

Cheers Fredrik Martenson

Hi, I need some advises on rails best practices when it comes to abstract/concrete models/classes in Rails. This is what I want to accomplish: A abstract type of page that holds base functionality like name, memberships, templates and other possible generic stuff. Then I want to have subclasses like ProjektPage or CoursePage and these classes should of course have it's own implementations and attributes. The only rails way I found on how to do this is with STI, however that is not a solution here because the subclasses of page will likely be very widespread.

It seems possible to me that you are going the wrong way about this. Are you wanting classes for the different view pages onto the underlying data? It would be more usual to have basic models such as User, Project, Course and so on then design the views to combine the data from the underlying models as you desire.

Colin

Yes, perhaps I do! I found this blog post about some techniques do add behavior to sub classes, a compromise. I am going to try this right away, thanks for your answer!