Tuesday, 20 August 2013

Pagination in rails 3

Pagination in rails 3

In my rails application I need to display the matching tweets .lets say
for example the matching results has 50 records, I need to display 10
records per page.I am getting the output which has all results but when I
use pagination its showing link to different pages , but when I click the
link to next page it says "string not matched". I tried different
combinations like 5 per page ,but when I click the link to the next page
it says "string not matched", but when I try without pagination it shows
all the results
My code for the controller
class TweetsController<ApplicationController
def index
city = params[:show]
search_term = params[:text]
search_term[" "] = "%"
@tweets = Tweets.where("tweet_text LIKE? ", "%#{search_term}%").paginate(
page: params[:page], per_page: 3)
My code for the view
<%= will_paginate @tweets %>
<% @tweets.each do |tweets| %>
<ul>
<li><%= tweets.id %></li>
<li><%= tweets.tweet_created_at %></li>
<li><%= tweets.tweet_source %></li>
<li><%= tweets.tweet_text %></li>
<li><%= tweets.user_id %></li>
<li><%= tweets.user_name %></li>
<li><%= tweets.user_sc_name %></li>
<li><%= tweets.user_loc %></li>
<li><%= tweets.user_img %></li>
<li><%= tweets.longitude %></li>
<li><%= tweets.latitude %></li>
<li><%= tweets.place %></li>
<li><%= tweets.country %></li>
<% end %>
</ul>
Anyone please help me with this

No comments:

Post a Comment