2
我有一个简单的搜索功能,但是当我搜索名称时,我需要输入名称完全相同,包括大写和小写。例如,如果我搜索“红宝石”,名称为“红宝石”它不会显示结果在轨道上的红宝石搜索(更改搜索字符串为小写)
视图源代码:
<div class="row center">
<%= form_tag pages_home_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search], :placeholder => "Search", :style => "text-align: center; font-size: 20px" %>
<button type="submit_tag" name="action" class="waves-effect waves-light btn">Search Tutorials</button>
<%end%>
控制器源码:
def index
@tutorials = Tutorial.search(params[:search])
end
模型源代码:
def self.search(search)
if search
where(["name LIKE ?","%#{search}%"])
else
all
end
我该怎么做,以便当用户键入搜索名称时,它显示结果,即使它是大写还是小写?
只适用于postgresql。 – mhutter
我使用postgresql,非常感谢 – prolog12345