伙计们,我正在尝试使用will_paginate
gem来实现分页,但它似乎没有用。我已将宝石添加到Gemfile
中,并尝试了以下代码:
控制器
def team_search
@teams = CareTeam.all.order('created_at ASC').paginate(page:params[:page], per_page: 10)
end
视图
<h1>Search for a team</h1>
<p>search for a team by team name</p>
<%= form_tag search_team_results_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search], placeholder:
"Search Teams By name", required: true %>
<%= submit_tag "Search", :name => nil %>
<% end %>
<%= will_paginate @teams %>
模型
def self.search(team_name)
if team_name
team_name.downcase!
self.where('LOWER(team_name) LIKE ?', "%#{team_name}%").order('created_at ASC')
else
CareTeam.all.order('created_at ASC')
end
end
当我导航到视图时,什么都没有显示。有人从上面分析出什么问题了吗?