Ruby on Rails - Pagination on Search Result

Ruby on rails - pagination on search result

The parameter :per_page defines entries count on each page. :total_entries is entries count that fetching from db in total.

I mean :per_page can't be larger than :total_entries

Ruby on rails - Kaminari - Paginate array of search results

try following code to carry your params to next page

= link_to_next_page @gigs, "Next Page", :remote => true, :params => params

Why is pagination on search result not working?

I think the problem is in this place: :page => @page . Where is the variable @page from ? You probably should send this variable when you call the search method of Post class

In the model:

def self.search(title, company, location_id, page)
if location_id.present?

paginate :conditions => ['title LIKE ? AND company LIKE ? AND location_id = ?', "%#{title}%", "%#{company}%", location_id].last(200),
:page => page,
:per_page => 20,
:order => "total DESC"

else

paginate :conditions => ['title LIKE ? AND company LIKE ?', "%#{title}%", "%#{company}%"].last(200),
:page => page,
:per_page => 20,
:order => "total DESC"

end
end

In the controller:

def search 
...
page = params[:page]
@posts = Post.search(title, company, location_id, page);
end

Rails search with will Paginate

You need to make changes in the controller level and UI side as well.

I am considering the parameters are coming to the controller from the UI side, and making changes in the query on the user controller.

Instead of all you need to create LIKE query

@user_list = User.all.paginate(:page => params[:page], :per_page => 100)

change it with

@user_list = User.where("name LIKE ? OR email LIKE ?", "%#{search_param}%", "%#{search_param}%").page(params[:page]).per(100)

hope it helps you to resolve your query.

Rails pagination does not load content for second page for search results

I changed the methods like below and it worked! As you can see, I cahnged the variable types to global in search_products method so that I can access it from show method.I also had to add show.html.erb under the in app/view/controller_name/ folder. Hope it helps others.

def show
@matching_products = ProductsUnderBid.search_products_under_bid(name: $search_name, category_id: $search_category,
location_id: $search_location_id, highest_bid: $search_highest_bid)
@matching_products = @matching_products.paginate(:page => params[:page],:per_page => 5)
get_already_placed_bids(@matching_products)
end

def search_products
$search_name = params[:search][:name]
$search_category = params[:search][:category_id].to_i
$search_location_id = params[:search][:location_id].to_i
$search_highest_bid = params[:search][:highest_bid].to_f
@matching_products = ProductsUnderBid.search_products_under_bid(name: $search_name, category_id: $search_category,
location_id: $search_location_id, highest_bid: $search_highest_bid)
@matching_products = @matching_products.paginate(:page => params[:page],:per_page => 5)
get_already_placed_bids(@matching_products)
end

Searchkick get all results when using pagination

My solution is to put this in it's own class (service class), then

class ProductFilter
attr_reader :search_params, :search_query, :pagination_params

def initialize(search_params, search_query, pagination_params)
@search_params = search_params
@search_query = search_query
@pagination_params = pagination_params
end

# Will return all records from searchkick, unpaginated
def filtered_products
Product.search(search_query, search_param_stuff)
end

# Will return all filtered_products & then paginate on that object
def paginated_products
filtered_products.records.paginate(pagination_params)
end

private
def search_param_stuff
search_params
end
end

In any case, searchkick's method for pagination actually works on the searchkick records object, so you can just pull the ES query (without passing in pagination params) in one method, then paginate on the filtered_products.records.



Related Topics



Leave a reply



Submit