Skip to content

Instantly share code, notes, and snippets.

## BAD 1
#
# => <p><select label="Language" name="lang"><option val... rather than <label...><select>
%p= text_field :title, :label => "Title"
%p= select :name => 'lang', :collection => @lang_opts, :label => 'Language'
%p= text_area :code, :label => "Code"
%p= text_area :explanation, :label => "Explanation (markdown)"
class Merb::BootLoader::MethodLogger < Merb::BootLoader
before Logger
def self.run
# do things
end
end
<script type="text/javascript">
$(document).ready(function(){
// Your code here
function councilFocus()
{
$("#council_image").hide("fast");
$("#nav1council").css("position", "relative");
$("#lnkAbout").css("position", "relative");
match(:subdomains => /(.*)/).to(:controller => ":subdomains[1]")
match('/').defer_to do |request, params|
sd = request.subdomains.first.capitalize
if Object.const_defined? sd
redirect url(:controller => sd.downcase)
else
false
end
end
class Exceptions < Application
# handle RecordInvalid exceptions (406)
def record_invalid
@errors = request.exceptions.first.errors
rename_error_fields!
if content_type == :html
render {:template => "#{request.controller}/#{request.params[:action]}"}
else
render
define_builder(Page) do |klass, overrides|
klass.new(:page_title => "foo.com", :page_id => 123)
end
define_builder(Summary) do |klass, overrides|
klass.new(:page_id => new_page.page_id, :user => new_user, :summary => "foobar")
end
define_builder(Country) do |klass, overrides|
# set up some presets
canada = { :iso => 'CA', :name => 'CANADA', :printable_name => 'Canada', :iso3 => 'CAN', :numcode => '124'}
usa = { :iso => 'US', :name => 'UNITED STATES', :printable_name => 'United States', :iso3 => 'USA', :numcode => '840' }
uk = { :iso => 'GB', :name => 'UNITED KINGDOM', :printable_name => 'United Kingdom', :iso3 => 'GBR', :numcode => '826' }
zimbabwe = { :iso => 'ZW', :name => 'ZIMBABWE', :printable_name => 'Zimbabwe', :iso3 => 'ZWE', :numcode => '716' }
# set up the default
country_attributes = canada
# check for a preset
overrides.process(:preset) do |preset|
require 'rubygems'
require 'gchart'
data = <<HERE
Net::HTTPServerException: 14
ActiveRecord::StatementInvalid: 126
no_data: 27814
Errno::EPIPE: 4
ScalaNet::UnknownHostException: 100359
EOFError: 9498
def set(reg: Reg, literal: byte): Code = {
return new Code() {
// implementation
}
}