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
class FullTimeEmployee < Employee
end
temp_employee.rb
class TempEmployee < Employee
end
student_employee.rb
development:
adapter: mysql
encoding: utf8
reconnect: false
database: dablog_development
pool: 5
username: root
password:
host: localhost
class PeopleController < ApplicationController
caches_page :index
end
def create
expire_page :action => :index
end
def update
expire_page :action => :index
end
class PeopleController < ApplicationController
cache_sweeper :person_sweeper, :only => [:create, :update, :destroy] ...
end
class PersonSweeper < ActionController::Caching::Sweeper
observe Person
def after_create(person)
expire_cache_for person
end
def after_update(person)
expire_cache_for person
end
class Company < ActiveRecord::Base
has_many :addresses
end
class Address < ActiveRecord::Base
belongs_to :company
end
class Company < ActiveRecord::Base
has_many :addresses
accepts_nested_attributes_for :addresses, :allow_destroy => true
end
<% form_for setup_company(@company) do |f| %>
<%= f.label :name %><br />
<%= f.text_field :name %><br />
<% f.fields_for :addresses do |address_form| %>
<%= f.label :street %><br />
<%= address_form.text_field :street %><br />
<%= f.label :city %><br />
<%= address_form.text_field :city %><br />
<%= f.label :post_code %><br />
module ApplicationHelper
def setup_company(company)
returning(company) do |c|
c.addresses.build if c.addresses.empty?
end
end
end