Skip to content

Instantly share code, notes, and snippets.

@mikeymicrophone
Created September 18, 2010 15:17
Show Gist options
  • Save mikeymicrophone/585745 to your computer and use it in GitHub Desktop.
Save mikeymicrophone/585745 to your computer and use it in GitHub Desktop.
class CommentsController
def index
@comments = if params[:book_id]
@scope_object = Book.find(params[:book_id])
@scope_object.comments
elsif params[:article_id]
@scope_object = Article.find(params[:article_id])
@scope_object.comments
else
Comment.all
end
end
end
Does Rails 3 provide any way to get the scope object without using a plugin like resourcelogic? Assume we are using nested routes like book_comments_path(@book)
What's the cleanest way to always get the comments scoped when you have a lot of different models that have comments?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment