私のユーザー インデックス ページでは、リスト全体をスキャンする代わりに電子メールでユーザーを検索できるように、上部に検索エンジンを配置しようとしています。ただし、次のエラーが表示されます。
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