Skip to content
Browse files

Changed LIKE to work with postgres

  • Loading branch information...
1 parent 95df97c commit 397f3887aff7fe6ac4264a3361dd97ea25416f70 @rogeliog committed
View
8 app/controllers/ruby_gems_controller.rb
@@ -1,12 +1,4 @@
class RubyGemsController < ApplicationController
- def index
- @ruby_gems = RubyGem.where("name like ?", "#{params[:q]}%").order("name")
- respond_to do |format|
- format.html
- format.json { render :json => @ruby_gems.map(&:attributes) }
- end
- end
-
def show
@ruby_gem = RubyGem.find (params[:id])
@ruby_gem.get_info
View
2 app/models/ruby_gem.rb
@@ -12,7 +12,7 @@ def self.top_ruby_gems size=5, offs=100
end
def self.search(params="")
- params.present? ? where("name LIKE ?", "%#{params}%") : scoped
+ params.present? ? where("name #{LIKE} ?", "%#{params}%") : scoped
end
def get_info
View
4 app/models/tutorial.rb
@@ -25,7 +25,7 @@ def markdown_body
end
def self.search(params="")
- params.present? ? where("title LIKE ?", "%#{params}%") : scoped
+ params.present? ? where("title #{LIKE} ?", "%#{params}%") : scoped
end
def self.top_tutorials size=5
@@ -47,7 +47,7 @@ def ruby_gems_names
def self.search_ruby_gems(ruby_gems)
puts ''
- ruby_gems.split(" ").map{ |rg| RubyGem.where("name LIKE ?", "#{rg}").first.id rescue nil}.uniq.compact.join(',')
+ ruby_gems.split(" ").map{ |rg| RubyGem.where("name #{LIKE} ?", "#{rg}").first.id rescue nil}.uniq.compact.join(',')
end
end
View
2 app/models/user.rb
@@ -10,7 +10,7 @@ class User < ActiveRecord::Base
has_many :authentications, :dependent => :destroy
def self.search(params="")
- params.present? ? where("name LIKE ?", "%#{params}%") : scoped
+ params.present? ? where("name #{LIKE} ?", "%#{params}%") : scoped
end
def admin?
View
7 config/initializers/like.rb
@@ -0,0 +1,7 @@
+if (ActiveRecord::Base.connection.adapter_name.downcase.include?('postgres'))
+ LIKE = 'ILIKE'
+else
+ LIKE = 'LIKE'
+end
+
+

0 comments on commit 397f388

Please sign in to comment.
Something went wrong with that request. Please try again.