Skip to content

Instantly share code, notes, and snippets.

View mgreenly's full-sized avatar

Michael Greenly mgreenly

View GitHub Profile
@mgreenly
mgreenly / warranty_steps.rb
Created November 16, 2011 04:15
Cucumber/RSpec onion layer 2
When /^I submit valid warranty claim details$/ do
@warranty_registration = Factory(:warranty_registration)
visit new_warranty_claim_path
fill_in 'Failure date', :with => Time.now.strftime("%m/%d/%Y")
fill_in 'Serial number', :with => @warranty_registration.serial_number
fill_in 'Customer name', :with => @warranty_registration.full_name
fill_in 'Customer phone', :with => @warranty_registration.phone
click_button "Create"
end
@mgreenly
mgreenly / gist:1397781
Created November 27, 2011 16:39
Decorator Pattern using SimpleDelegator
require 'delegate'
class Foo
attr_accessor :fname, :lname
def initialize(fname, lname)
@fname, @lname = fname, lname
end
end
# create a foo object
@mgreenly
mgreenly / gist:1474920
Created December 14, 2011 02:15
ignore column in active record
class User < ActiveRecord::Base
@@ignore_attr = ['lname']
def arel_attributes_values(include_primary_key = true, include_readonly_attributes = true, attribute_names = @attributes.keys)
attrs = super(include_primary_key, include_readonly_attributes, attribute_names)
attrs.delete_if {|key,value| @@ignore_attr.include?(key.name) }
puts attrs.inspect
attrs
end
end
@mgreenly
mgreenly / gist:1490808
Created December 17, 2011 17:26
$HOME/.ssh/config
# $HOME/.ssh/config
Host *compute-1.amazonaws.com
User ubuntu
StrictHostKeyChecking no
UserKnownHostsFile /dev/null
IdentityFile ~/.ssh/your-ec2-key
ServerAliveInterval 30
ServerAliveCountMax 120
@mgreenly
mgreenly / bootstrap_style.html
Created December 27, 2011 02:49
rails form formatting for twitter bootstrap #1
<!-- without error -->
<div class="clearfix">
<label for="bar">Bar</label>
<div class="input">
<input id="foo_bar" name="foo[bar]" size="30" type="text">
</div>
</div>
<!-- with error -->
<div class="field">
@mgreenly
mgreenly / bootstrap_style.html
Created December 27, 2011 02:58
rails form formatting for twitter bootstrap #2
<!-- without error -->
<div class="clearfix">
<label for="bar">Bar</label>
<div class="input">
<input id="foo_bar" name="foo[bar]" size="30" type="text">
</div>
</div>
<!-- with error -->
<div class="clearfix error">
@mgreenly
mgreenly / environment.rb
Created December 27, 2011 03:01
rails form formatting for twitter bootstrap #3
# ./config/environment.rb
ActionView::Base.field_error_proc = Proc.new {|html, instance| html }
@mgreenly
mgreenly / boot_strap_form_builder.rb
Created December 27, 2011 03:03
rails form formatting for twitter bootstrap #4
# ./app/helpers/boot_strap_form_builder.rb
class BootStrapFormBuilder < ActionView::Helpers::FormBuilder
def text_field(method, options={})
t = @template
t.content_tag(:div, :class => "clearfix#{' error' unless @object.errors[method].blank?}") {
t.concat(t.label_tag method)
t.concat(t.content_tag(:div, :class => "input#{' error' unless @object.errors[method].blank?}") {
t.concat(super method)
@mgreenly
mgreenly / _form.html.erb
Created December 27, 2011 03:42
rails form formatting for twitter bootstrap #5
<%= form_for(@foo, :builder => BootStrapFormBuilder) do |f| %>
<%= f.error_explanations %>
<%= f.text_field :bar %>
<%= f.submit %>
<% end %>
I18n.t!(:some_key) rescue nil || :some_key.to_s