0
在我的用戶索引頁上我試圖在頂部有一個搜索引擎,以便您可以通過電子郵件搜索用戶而不是掃描整個列表。不過,我得到的錯誤:Rails:will_paginate +簡單的搜索引擎錯誤:未定義的方法`total_pages'
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
hey zach。當我將控制器的索引動作的第三行更改爲'@users = User.search(params [:search])。頁面(params)時,它仍然給我'未定義的方法'頁面'# [:page])。per_page(10)' –
Edmund
查看更新後的答案。 –