Q:

Slimming up scoped filters in rails controller

I'm putting filtering functionality into an application (Rails 4.1beta) - I did this by creating scopes on the Item model, passing a scope through the request params and doing a case statement in the index action. It all works but there's a code smell I'm trying to get rid of in the index action of one of the controllers;
def index                    
  case params[:scope]        
    when "recent"            
      @items = Item.recent
    when "active"
      @items = Item.active
    when "inactive"
      @items = Item.inactive
    else
      @items = Item.all
  end
end 

It all feels a little too rigid / verbose. I'd really like to just do something like this;
def index
  @items = Item.send(params[:scope])
end

but then I leave the application wide open to people calling methods on the Item class. Whacking conditions in there kinda defeats the point of what I'm trying to achieve. 
Is there some rails magic I'm missing that can help me here?

A:

You can use different controllers to do each of these.
inactive_items_controller.rb
def index
  @items = Item.inactive
end

recent_items_controller.rb
def index
  @items = Item.recent
end

etc.
Or you can just move you logic you have above to the model
Item model
def self.custom_scope(scope)
  case scope   
  when "recent"            
    Item.recent
  when "active"
    Item.active
  when "inactive"
    Item.inactive
  else
    Item.all
  end
end

or
def self.custom_scope(scope)
  recent   if scope == 'recent'
  active   if scope == 'active'
  inactive if scope == 'inactive'
  scoped   if scope.blank?
end

And then in your index
@items = Item.custom_scope params[:scope]

