我最近上傳了我的應用程序到heroku,由於postgresql,區分大小寫不起作用,我想知道如何解決這個問題?我的代碼如下:Heroku大小寫敏感
relation = Game.gamsearch(params[:gamsearch])
relation = Game.consearch(params[:consearch]) if params[:consearch].present?
relation = Game.gensearch(params[:gensearch]) if params[:gensearch].present?
relation = Game.where("game_name LIKE ?", "#{params[:game_name]}%") if params[:game_name].present?
relation = Game.where("console = ?", params[:console]) if params[:console].present?
視圖代碼:
<%= form_tag games_path, :controller => 'games', :action => 'gamsearch', :method => 'get' do %>
<%= text_field_tag :gamsearch, params[:gamsearch] %>
<%= submit_tag t('.searchb'), :game_name => nil %>
<% end %>
這是型號代碼:
def self.gensearch(*args)
#search for games by their genre
return [] if args.blank?
cond_text, cond_values = [], []
args.each do |str|
next if str.blank?
cond_text << "(%s)" % str.split.map{|w| "genre LIKE ? "}.join(" OR ")
cond_values.concat(str.split.map{|w| "%#{w}%"})
end
all :conditions => [cond_text.join(" AND "), *cond_values]
末
太好了。我該如何處理其他搜索,特別是列表中的第一個,或者這是你的知識之外 – user1222136 2012-04-24 14:02:30
你需要在gamsearch方法中使用ILIKE,對於搜索和gensearch也是如此。沒有看到這些方法,這是超出我的知識:) – 2012-04-24 14:05:12
我已更新我的文章:) – user1222136 2012-04-24 14:10:06