I am usins scope in my controller to filter my models :
@hotels = Hotel.scoped
@hotels = @hotels.country(params[:country_id]) unless params[:country_id].blank?
@hotels = @hotels.city(params[:city_id]) unless params[:city_id].blank?
@hotels = @hotels.hoteltype(params[:hotel_type]) unless params[:hotel_type].blank?
@hotels = @hotels.theme(params[:hotel_theme]) unless params[:hotel_theme].blank?
@hotels = @hotels.prices(params[:hotel_prices]) unless params[:hotel_prices].blank?
@hotels = @hotels.services(params[:hotel_services]) unless params[:hotel_services].blank?
count = @hotels.count
@hotels.paginate :page => params[:page], :per_page => 12
But it didn't work, still has all @hotels in my @hotels variable.
What did i do wrong?
If you have questions about Rails or plugins, please use forums or Stackoverflow. Issues are when you can provide a failing test.
@hotels = @hotels.paginate :page => params[:page], :per_page => 12
And moreover you should use a plugin like meta_search. Remember : Thin Controller, Fat Model.
Thank you for help !!! An sorry to make a post on the wrong place.
@Ditchou, your problem is most likely in your filter code rather than pagination. Ensure that your filters work properly and, most importantly, that they don't load all records themselves! That means avoiding all() method, find(:all) or to_a calls on these scopes.
After that just perform pagination on the resulting "scope", and all should be fine. Keep an eye on your development.log to check that the generated SQL query is correct.