我是 Ruby 新手,所以如果这是一个愚蠢的问题,我深表歉意。我正在尝试将 will_paginate 与搜索字段一起使用,并且无法使其不区分大小写。谢谢你的帮助!
来自 rating_controller.rb:
def index
@ratings_by_name = Rating.paginate(:order => 'name ASC', :page => params[:page], :per_page =>10, :conditions => ['name like ?', "%#{params[:search]}%"])
@ratings_by_score = Rating.paginate(:order => 'score DESC', :page => params[:page], :per_page =>10, :conditions => ['name like ?', "%#{params[:search]}%"])
respond_to do |format|
format.html # index.html.erb
format.json { render json: @ratings_by_name }
end
end
来自 index.html.erb:
<div class="tabbable">
<ul class="nav nav-pills">
<li class="active"><a href="#tab1" data-toggle="tab">By Name</a></li>
<li><a href="#tab2" data-toggle="tab">By Score</a></li>
<li><form class="navbar-search">
<input type="text" class="search-query span3" placeholder="Search" name="search">
<div class="icon-search"></div>
</form></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab1">
<% @ratings_by_name.each do |rating| %>
<div class="rating">
<div class="row">
<div class="span7">
<strong><%= rating.name %></strong>
<div class="meta">
| <%= link_to 'View', rating %> |
<span class="admin">
<%= link_to 'Edit', edit_rating_path(rating) %> |
</span>
Rated on <%= rating.when_rated %>
</div>
</div>
<div class="span1">
<%= rating.score %>
</div>
</div>
</div>
<% end %>