Tag: 有范围

将current_scopes传递给搜索

我正在使用非常有用的has_scope gem。 我有一个通过在链接中传递范围创建的索引页面。 在那个索引页面上,我可以查询current_scopes。 我在该页面上有一个非常标准的搜索范围搜索表单,但使用它会返回没有任何范围的结果。 如何将current_scopes传递给搜索? 我尝试使用隐藏字段但无法使其工作。 我想如果我可以在一个链接中传递范围,我应该能够以一种forms传递它们但是在谷歌搜索后我不确定这是真的。 搜索表单 {:method => :post} do |f| %> 指数法 def index @user = User.find_by_username(params[:user_id]) @search = apply_scopes(@user.collections).search(params[:q]) @search.sorts = ‘created_at desc’ if @search.sorts.empty? @collections = @search.result.paginate(page: params[:page]) end

带有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 […]