带有has_scope的Rails 4:无声地失败

我有一个Rails 4.0.0应用程序,并希望包含has_scope gem。

非常简单和直接的资源:

模型:

class Thing  client { where(:client => client)} scope :by_name, -> name { where(:name => name)} 

控制器:

 class ThingsController  [:index, :edit] has_scope :by_client, :type => :integer has_scope :by_name .... def index @things = apply_scopes(Thing).all puts current_scopes end 

current_scopes始终是一个空哈希,无论应用什么范围,Thing.all都会传递给视图。 范围本身是正确的,并正确返回过滤后的记录参数是有的:例如:

 Started GET "/things?client=113" for 127.0.0.1 at 2014-07-26 16:07:32 +0200 Processing by ThingsController#index as HTML Parameters: {"client"=>"113"} 

这个设置有什么问题。 我没有警告,没有方法丢失等等。只是完整的事情清单。 我错过了一些配置选项还是其他什么?

得到它,在这种情况下,范围适用于表colums。 这解决了它:

 scope :by_client, -> client { where(:client_id => client)} 

而不是一个

 has_scope :by_client 

和参数

 {"by_client"=>"113"} 

够了

基于我通过has_scope文档的简要阅读,您提供的参数是错误的,需要更改为

 { "by_client" => { "client" => "113" } } 

并且您的控制器需要将has_scope更改为

 has_scope :by_client, :using => :client, :type => :integer