Skip to content

Instantly share code, notes, and snippets.

View mwmitchell's full-sized avatar

Matt Mitchell mwmitchell

View GitHub Profile
class Product
include DataMapper::Resource
include Paperclip::Resource
property :id, Serial
property :name, String, :nullable => false, :index => :unique
property :description, String
property :price, Float, :default=>0.0
merb : worker (port 4000) ~ Started request handling: Sun Oct 19 14:52:21 -0400 2008
merb : worker (port 4000) ~ Routed to: {"format"=>nil, "action"=>"new", "controller"=>"admin/products"}
merb : worker (port 4000) ~ Params: {"format"=>nil, "action"=>"new", "controller"=>"admin/products"}
~ SELECT "id", "name" FROM "tags" ORDER BY "id"
merb : worker (port 4000) ~ undefined method `image_1' for #<Product:0x2ae9000> - (NoMethodError)
/opt/local/lib/ruby/gems/1.8/gems/merb-helpers-0.9.9/lib/merb-helpers/form/builder.rb:274:in `send'
/opt/local/lib/ruby/gems/1.8/gems/merb-helpers-0.9.9/lib/merb-helpers/form/builder.rb:274:in `control_value'
/opt/local/lib/ruby/gems/1.8/gems/merb-helpers-0.9.9/lib/merb-helpers/form/builder.rb:32:in `bound_file_field'
/opt/local/lib/ruby/gems/1.8/gems/merb-helpers-0.9.9/lib/merb-helpers/form/helpers.rb:348:in `file_field'
/Users/mwm4n/Projects/fw-windows-merb/app/views/admin/products/_fields.html.erb:49:in `__Users__mwm4n__Projects__fw__windows__merb__app__views__admin__p
# solr query builder
response = solr.search do |s|
s.query ''
s.phrase_query ''
s.filter :author, 'ernst'
s.phrase_filter :location, 'South'
s.fq '' # override / merge s.filter and s.phrase_filter ?
s.q '' # override / merge s.query and s.phrase_query ?
end
#
# A hash modifier that creates method readers from key names.
# NOTE: reader methods are created recursively.
# The method names are the same as the key names,
# except that the values are snake-cased, for example:
# - QTime -> q_time
# - debugQuery -> debug_query
#
class RSolr::Ext::HashMethodizer
# config/initializers/blacklight.rb
# Rails will load this file once during the boot/start-up process
# http://ryandaigle.com/articles/2007/2/23/what-s-new-in-edge-rails-stop-littering-your-evnrionment-rb-with-custom-initializations
#
# Access the blacklight config from anywhere, like this: Blacklight.config[:solr][:url]
# SHARED
Blacklight.configure do |config|
# The basic solr field mapping
config[:display_fields] = {
# This will execute the Git revision parsing on the *remote* server rather than locally
# from "filmprog" on #capistrano/irc.freenode.net
set :real_revision, lambda { source.query_revision(revision) { |cmd| capture(cmd) } }
#
# A module to help marc related solr documents
#
# Example:
# docs.each{|d| d.extend(SolrMARCDocument) if d[:marc_display] }
#
module SolrMARCDocument
def marc
@marc ||= (
# rails action
def in_bg
pid = fork {
10.times do |i|
puts "WAITING .... #{i}"
sleep 1.0
end
}
Process.detach(pid)
render :text=>pid.to_s
module ExtendedMeta
def extended_by
ancestors = class << self; ancestors end
ancestors.select { |mod| mod.class == Module } - [ Object, Kernel ]
end
# just like kind_of? but can use a string instead of a module/constant
def extended_by?(mod)
begin
solr = RSolr.connect
solr.extend RSolr::Ext::Connection
full_response = solr.find({:q=>'*:*'}, :response=>true)
one_doc = solr.find({:q=>'blah'}, :first=>true)
one_doc = solr.find_by_id(10)