Hi,
I have an index page with searchbox and with pagination, it worked well
when I tried to make pagination with javascript, itworked for the first
page but not the second
I think the problem is to pass the value of the search box to the script
of
pagination
here is my code:
index.hmtl.erb
<%= text_field_tag ‘q’, params[‘q’] %>
<%= render 'layouts/posts' %>
<% if [email protected]? %>
<%= link_to 'Load More Posts', post_path(:page =>
@posts.next_page),
:class => 'load-more-posts', :remote => true if @posts.next_page %>
<% end %>
-----------------------------------------------------------------
_posts.html.erb
<% if [email protected]? && @posts.size > 0 %>
<% @posts.each_with_index do |post| %>
<%= post.title %>
<%= post.body %>
<% end %>
<% end %>
-----------------------------------------------------
respond_to do |format|
format.html # index.html.erb
format.json { render json: @posts }
format.js
end
end
The problem with this code is thatI can’t go to the next page beause the
params q is null with ajax call
when I delete the condition it works well
thank you fo the help
Thx for the answer
but my problem is when I have a query, I am unable to go to the second
page
I get @posts as nil object, it is like paginating with ajax do not
submit
the query when changing the page
I already posed my code, I have a paginated list with will_paginate
obtained with a search query
the first page is shown correctly but the second is not shown with the
js
code because the query is not submitted for the second page with ajax
code
the params[:q] is nil when I navigate to the second page
def index
*if !params[:q].nil? *