Skip to content

Instantly share code, notes, and snippets.

View overture8's full-sized avatar

Phil McClure overture8

  • Stora
  • Belfast, Northern Ireland
View GitHub Profile
require 'md5'
module CommentsHelper
def gravatar_url_for(email = null, size = 80)
hash = MD5::md5(email.downcase)
image_src = "http://www.gravatar.com/avatar/#{hash}?s=#{size}"
end
end
<%= image_tag(gravatar_url_for(comment.email)) %>
map.connect 'archives/:year/:month',
:controller => 'posts',
:action => 'find_by_date',
:year => /\d{4}/,
:month => /(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)/
def find_by_date
@posts = Post.find(:all,
:conditions => ["monthname(created_at) = ? AND year(created_at) = ?",
params[:month], params[:year]])
render :action => "index"
end
def to_param
"#{id}-#{title.gsub(/[^a-z0-9]+/i, '-')}"
end
class Report
def create_report
# Left blank, sub-classes will implement this
end
end
class XmlReport < Report
def create_report
puts "I am an Xml Report"
end
class ReportGenerator
def print_report(report_type)
report_type.create_report
end
end
rep_gen = ReportGenerator.new
my_reports = [XmlReport.new, TextReport.new, HtmlReport.new, PdfReport.new]
my_reports.each do |report|
rep_gen.print_report(report)
end
user = User.find(1)
user_orders = user.orders
<div class="span-6"></div>