aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
authorJoe Sak <joe@joesak.com>2011-06-21 22:52:21 -0500
committerJoe Sak <joe@joesak.com>2011-06-21 22:52:21 -0500
commit3b975e0d77b4e54957372f39599adca5e731fdeb (patch)
tree18f4442711ffa086938fbbb5b4db032f5aae558d /app/controllers
parentbce2877b2a13619841c77b6de8e87d4acf7abd53 (diff)
downloadrefinerycms-blog-3b975e0d77b4e54957372f39599adca5e731fdeb.tar.gz
refinerycms-blog-3b975e0d77b4e54957372f39599adca5e731fdeb.tar.bz2
refinerycms-blog-3b975e0d77b4e54957372f39599adca5e731fdeb.zip
postgreSQL is picky about doing a LIKE query
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/admin/blog/posts_controller.rb16
1 files changed, 14 insertions, 2 deletions
diff --git a/app/controllers/admin/blog/posts_controller.rb b/app/controllers/admin/blog/posts_controller.rb
index 9fdc638..29ffb01 100644
--- a/app/controllers/admin/blog/posts_controller.rb
+++ b/app/controllers/admin/blog/posts_controller.rb
@@ -12,9 +12,21 @@ class Admin::Blog::PostsController < Admin::BaseController
end
def tags
+ op = case ActiveRecord::Base.connection.adapter_name.downcase
+ when 'postgresql'
+ 'SIMILAR TO'
+ else
+ 'LIKE'
+ end
+ wildcard = case ActiveRecord::Base.connection.adapter_name.downcase
+ when 'postgresql'
+ '.*'
+ else
+ '%'
+ end
@tags = BlogPost.tag_counts_on(:tags).where(
- ["tags.name LIKE ?", "%#{params[:term].to_s.downcase}%"]
- ).map { |tag| {:id => tag.id, :value => tag.name}}
+ ["tags.name #{op} ?", "#{wildcard}#{params[:term].to_s.downcase}#{wildcard}"]
+ ).map { |tag| {:id => tag.id, :value => tag.name}}
render :json => @tags.flatten
end