Skip to content

Instantly share code, notes, and snippets.

@jakcharlton
Forked from terryjray/product.rb
Created September 5, 2013 20:32
Show Gist options
  • Save jakcharlton/6455763 to your computer and use it in GitHub Desktop.
Save jakcharlton/6455763 to your computer and use it in GitHub Desktop.
class Product < ActiveRecord::Base
# our hstore column, make sure gem 'activerecord-postgres-hstore' is in your Gemfile
# and you've run: rails g hstore:setup
serialize :data, ActiveRecord::Coders::Hstore
# name is a string col
attr_accessible :data, :name
def self.search(query)
where("name @@ :q or CAST(avals(data) AS text) @@ :q", q: query)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment