在我的用户索引页面上,我试图在顶部有一个搜索引擎,以便您可以通过电子邮件搜索用户,而不是扫描整个列表。但是,我收到错误:
undefined method 'total_pages'
当我搜索任何术语时。
任何人都可以帮忙吗?谢谢!
用户/index.html.erb
<h1>All users</h1>
<%= form_tag users_path, :method => "get" do %>
<%= label_tag(:search, "Search for user by email:") %>
<%= text_field_tag :search, params[:search] %>
<%= submit_tag "Search", :name => nil %>
<% end %>
<%= will_paginate @users %>
<br>
<% @users.each do |user| %>
<div>
<%= link_to (image_tag user.profilepic? ? user.profilepic : "questionmark.png", :size => "50x50"), user_path(user) %>
<%= link_to user.name, user_path(user) %> (<%= user.email %>)
<% unless current_user.friends.include?(user) || current_user == user %>
<span class="floatright"><%= link_to "Add friend", user_friends_path(:user_id => current_user.id, :friend_id => user.id), :method => :post %></span>
<% end %>
<% if current_user.friends.include?(user) %>
<span class="floatright"><%= link_to "Remove friend", user_friends_path(:user_id => current_user.id, :friend_id => user.id), :method => :delete, :confirm => "Are you sure you want to remove #{user.name} from your friends?" %></span>
<% end %>
</div>
<% end %>
用户控制器
def index
if params[:search]
@users = User.search(params[:search])
else
@users = User.order("email").page(params[:page]).per_page(10)
end
end
用户模型
def self.search(search)
find(:all, :conditions => ['email LIKE ?', "%#{search}%"])
end