Good notes posted by noxyu3m
RSS feed
render_collection
You can wrap render in helpers. For example, render_collection. In app/helpers/application.rb:
module ApplicationHelper def render_collection(name, collection) render :partial => "shared/#{name}", :collection => collection end end
In views:
<h2>Comments</h2> <%= render_collection :comments, @photo.comments %>

Keep your controllers clear
When you use redirect_to or render with flash[:notice] or flash[:error], you can define some helper methods in your ApplicationController (or somewhere you want):
class ApplicationController < ActionController::Base protected %w(notice error).each do |message| class_eval <<-END_EVAL def redirect_#{message}(url, message) flash[:#{message}] = message redirect_to url end def render_#{message}(action, message) flash[:#{message}] = message render :action => action end END_EVAL end end
Now you have four methods - redirect_notice, redirect_error, render_notice and render_error.

Custom annotation types
For group work you may need something more than FIXME, OPTIMIZE and TODO. Just create new rake file and place it to lib/tasks:
require 'source_annotation_extractor' task :notes do SourceAnnotationExtractor.enumerate "WTF|OMG", :tag => true end namespace :notes do desc "Enumerate all WTF annotations" task :wtf do SourceAnnotationExtractor.enumerate "WTF" end desc "Enumerate all OMG annotations" task :omg do SourceAnnotationExtractor.enumerate "OMG" end end
or create an array of new types and generate tasks dynamicaly.

Loading fixtures in migrations
This helper is wrapper around Fixtures#create_fixtures and just load fixtures from specified directory (db/migrate/data by default):
class ActiveRecord::Migration def self.load_data(filename, dir = 'db/migrate/data') Fixtures.create_fixtures(File.join(RAILS_ROOT, dir), filename) end end
It is usefull for tables with data like country list:
class CreateCountries < ActiveRecord::Migration def self.up create_table :countries do |t| t.string :name, :code, :null => false t.timestamps end load_data :countries end def self.down drop_table :countries end end

Migration helpers
You can add your own migration helpers as references:
Code example
class ActiveRecord::ConnectionsAdapters::TableDefinition def counter_caches(*args) args.each { |col| column("#{col}_count", :integer, :default => 0) } end end class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :first_name, :last_name, :email t.counter_caches :photos, :messages t.timestamps end end def self.down drop_table :users end end