Skip to content

Instantly share code, notes, and snippets.

Phil McClure overture8

Block or report user

Report or block overture8

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gravatar_helper.rb
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
View route_month_urls.rb
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)/
View find_by_date.rb
def find_by_date
@posts = Post.find(:all,
:conditions => ["monthname(created_at) = ? AND year(created_at) = ?",
params[:month], params[:year]])
render :action => "index"
end
View to_param_url.rb
def to_param
"#{id}-#{title.gsub(/[^a-z0-9]+/i, '-')}"
end
View override_method.rb
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
View using_abstraction.rb
class ReportGenerator
def print_report(report_type)
report_type.create_report
end
end
View using_abstraction2.rb
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
View assoc_object.rb
user = User.find(1)
user_orders = user.orders
You can’t perform that action at this time.