我是Ruby的新手,所以如果这是一个愚蠢的问题我会道歉。我正在尝试将will_paginate与搜索字段一起使用,并且在使其不区分大小写时遇到问题。谢谢你的帮助!
来自ratings_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 %>
答案 0 :(得分:0)
尝试使用“LOWER(name)”作为订单
@ratings_by_name = Rating.paginate(:order => 'LOWER(name) ASC', :page => params[:page], :per_page =>10, :conditions => ['name like ?', "%#{params[:search]}%"])