jeudi 26 mai 2016

Filtering models with pagination only filters first page - rails 3

I have a model which I am filtering based on some parameters given by the user. The filtering works just fine but once I start using pagination, only the records from the first page are filtered and the others are ignored. This is my code in the controller for filtering:

 @start_date = params[:start_date]
 @registers = Register.all.order("payment_date DESC").page(params[:page]).per(params[:all] ? nil : Kaminari.config.default_per_page)
 @registers.delete_if { |r| !(r.payment_date <= @end_date && r.payment_date >= @start_date) if (@start_date.present? && @end_date.present?) }

And in the view I use <%= paginate @registers %> to paginate the list.

Aucun commentaire:

Enregistrer un commentaire