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!:) Cheers Fredrik Martenson -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
2010/1/13 fredd <fredrik.martenson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>:> 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> > 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!:) > > Cheers > Fredrik Martenson > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en. > > > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Yes, perhaps I do! I found this blog post about some techniques do add behavior to sub classes, http://robots.thoughtbot.com/post/159808315/a-compromise. I am going to try this right away, thanks for your answer! On 13 Jan, 12:32, Colin Law <clan...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> 2010/1/13 fredd <fredrik.marten...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > > > 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 > > > > > > > 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!:) > > > Cheers > > Fredrik Martenson > > > -- > > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > > For more options, visit this group athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.