heartcombo/has_scope

scope not activated from params

leonardochen opened this issue · 4 comments

I transferred an app from one server to another, and my has_scopes stopped working. It's returning all results instead of filtering them. The controller seems to have no knowledge of it. I see the params[ ], but current_scopes does not show anything.
This app is still running rails 3.2.19 and has_scope 0.5.1

I put this code in my View

<p>LCC <%= current_scopes %> <%= params %></p>

And it returned this

LCC {} {"utf8"=>"✓", "by_codigo"=>"95", "by_nome"=>"", "button"=>"", "action"=>"index", "controller"=>"produtos"}

Current_scopes is completely blank. Here is my controller, plain vanilla

class ProdutosController < ApplicationController
  has_scope :by_nome
  has_scope :by_codigo

The model scope is working on the console, but it's just not being activated.
Your gem was working great on my previous server, which was running 3.2.15 with 0.5.1. I just can't see why it stopped working.

Any ideas of what could be happening? I may return to 3.2.15 but I'd rather not.
Thanks!

Still investigating... if I apply the scope manually in the controller it goes through as expected.

def index
  @produtos=apply_scopes(Produto).page(params[:page])
end

Current_scopes is now returning

{:by_codigo=>"9"}

I'm not sure why my controller is not calling it. Both servers are using InheritedResources 1.3.1

Can you please provide a sample application that reproduces the error?

If it's any help, I had this problem just now. In my case I had a default value which didn't match the type of the scope, in which case the param value is set to nil instead, and the scope is not applied (unless you set allow_blank). Your example doesn't set a default, so it's probably not your issue, but it might help someone else.

Sorry, I think there was something wrong with my installation as I cannot reproduce the issue. I'll close the ticket. Thanks.