set query outside the if otherwise the ransack search in the template crashes