Skip to content

Instantly share code, notes, and snippets.

class ProductsController < ApplicationController
def search
Product.search do
fulltext 'cities'
with :used, false
end
end
end
Product.where("name LIKE '%?%'", 'cities').all
# citi is the stem of cities
citi => city
# copi is the stem of copies
copi => copy
gem 'sunspot_rails'
gem 'sunspot_solr' # optional pre-packaged Solr distribution for use in development
rails g sunspot_rails:install
rake sunspot:solr:start
@mikepack
mikepack / gist:2417873
Created April 19, 2012 02:08
Exhibits and renderers
class RailsTextPostRenderer
def initialize(context)
@context = context
end
def render(model)
@context.render(partial: "/posts/text_body", locals: {post: model})
end
end
@mikepack
mikepack / decorate.js
Created April 25, 2012 06:07
Decorators in JS
function SomeClass() {}
SomeClass.prototype.do_it = function() { alert('doin it!'); }
s = new SomeClass();
function Decorator(klass) { this.__proto__ = klass.__proto__; }
d = new Decorator(s)
d.do_it()
@mikepack
mikepack / gist:3244024
Created August 3, 2012 03:18
Testing blocks

How do you test this?

I want to test that something receives #var from inside the block.

I realize this might be a code smell.

something = Struct.new(:var).new
some_method do
 something.var