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
You have an error in
search_term[" "] = "%"
line. If it should replace whitespace with "%", it should be:
search_term.gsub!(/\s/, '%')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.