≡

wincent.dev

  • Products
  • Blog
  • Wiki
  • Issues
You are viewing an historical archive of past issues. Please report new issues to the appropriate project issue tracker on GitHub.
Home » Issues » Feature request #1325

Feature request #1325: Possible simplification of comments controller

Kind feature request
Product wincent.dev
When 2009-06-22T11:33:02Z
Status open
Reporter Greg Hurrell
Tags no tags

Description

Reading this article on RESTful routing, comments, and marking things as spam, the author suggests the following.

Given a couple of commentable resources like these:

map.resources :bookmarks, :has_many => [:comments]
map.resources :posts,     :has_many => [:comments]

You will find yourself writing helpers like this:

def spam_comment_url(comment)
  case o = comment.commentable
    when Post
      spam_post_comment_url(o, comment)
    when Bookmark
      spam_bookmark_comment_url(o, comment)
    end
  end
end

Which they claim is evidence of the fact that you need a new top-level resource with an additional non-REStful action:

# First define the top-level comment resource
map.resources :comments, :member => {:spam=>:post}

# then add a shallow collection under each of the commentables
map.resources :bookmarks do |bookmarks|
  bookmarks.resources :comments, :shallow=>true
end

map.resources :posts do |posts|
  posts.resources :comments, :shallow=>true
end

I'm inclined to think that the additional action probably isn't required but it could definitely make some things a little bit cleaner and easier, so it's something to think about.

Comments

    Add a comment

    Comments are now closed for this issue.

    • contact
    • legal

    Menu

    • Blog
    • Wiki
    • Issues
    • Snippets