The reason for the @scope variable is that you might need to know the scope of your request outside the single action. Let's assume you want to display the number of records in your view. You need to know whether you are filtering by category or not. In this case, you simply need to call @scope.count or @scope.my_named_scope.count instead of repeating each time the check on params[:category_id].

This approach works well if your views, the one with category and the one without category, are quite similar. But what happens when the listing filtered by category is completely different compared to the one without a category? This happens quite often: your category section provides some category-focused widgets while your article section some article-related widgets and filter. Also, your Article controller has some special before_filters you might want to use, but you don't have to use them when the article listing belongs to a category.

Now the listing filtered by category is managed by the CategoriesController and it inherits all the controller filters, layouts, settings... while the unfiltered listing is managed by the ArticlesController.

This is usually my favorite choice because with an additional action you don't have to clutter your views and controllers with tons of conditional checks.

However, depending on what other nested resources you have for the model, sticking with this approach can get quite tedious. In which case, using a plugin like resource_controller or make_resourceful will make this much simpler.

i'm already using resource_controller but how would you paginate the resultset and render different views without overriding resource_controller "magic" method?
–
knoopxNov 28 '09 at 12:25

You could override the collection setter method and tell it how you want to paginate the articles. There's example code in the resource_controller readme under "Helpers".
–
Michael RichardsNov 28 '09 at 14:03

I often like to separate those actions. When the resulting actions are very similar you can separate the scopes inside the controller easy by seeing if params[:category_id] is present etc (see @SimoneCarletti answer).

Normally separating actions in the controller by using custom routes gives you most flexibility and clear results. Following code results in normal route helper names but the routes are directed to specific actions in controller.