[rails-oceania] Making Comments Nested, Polymorphic and Self Join(able)

72 views
Skip to first unread message

Ben Sand

unread,
May 18, 2010, 9:07:01 AM5/18/10
to rails-oceania
Hi,

Working on a polymorphic comments model and having trouble organising the routing and controllers.

In an ideal world:
Feeds have many articles
Comments are on Feeds, Articles and on Comments themselves.
There will be a restriction on depth of comments on comments, eg. max 3 levels.
---
where we are at now:

class Feed < ActiveRecord::Base
    has_many :articles
    has_many :comments, :as => :commentable
...
class Article < ActiveRecord::Base
    belongs_to :feed
    has_many :comments, :as => :commentable
...
class Comment < ActiveRecord::Base
    belongs_to :commentable, :polymorphic => true
    # i'd like to add comments on comments through a self join here at some point too.

The problem is, comments can apply to both nested levels of the heirarchy, ie.
/feeds/1/articles/5/comments
/feeds/1/comments

---
Solutions attempted:

First tried here: http://railscasts.com/episodes/154-polymorphic-association

then went on to:
http://danielbradberry.com/?p=355#content
and got stuck when we couldn't work out how the functions should be called

then tried this: http://blog.opensteam.net/past/2008/11/26/polymorphic_controller_nested_routes_polymorphic/
but I got stuck trying to apply their method to nested routes.
---

The polymorphic controllers and route handling seems really ugly - is there any definitive solution to this, that also handles self joins and nesting nicely?

How does shallow routing stack up against polymorphic resources?

--
You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group.
To post to this group, send email to rails-...@googlegroups.com.
To unsubscribe from this group, send email to rails-oceani...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
Reply all
Reply to author
Forward
0 new messages