= Best Practices by Marcel Molina Jr. and Michael Koziarski class TheRailsWay < Blog authored_by :james authored_by :koz delegate :jamis, :to => :marcel end "http://www.therailsway.com/" Lots of stuff to tell you how you could do it, but almost nothing about how you _should_ do it. 6-7 actions and 6-7 lines of code pr. action Most of the time, you really just want to have models having conversations with each other That will make the models fat, but your code more readable Add a last_expired property to the Expense model instead of looking up directly in the controller Recommends Smalltalk pattern book (?) People who start out coding Rails, often think and code in terms of SQL == Best practice: @credit_card.transactions.create! params[:transaction] @credit_card.transaction.find(:all, :conditions => ["authorized_at < ", 3.hours.ago]) == Scoped class Transaction def self.pending_approval ... end end Transaction.pending_approval will give you all pending approvals @credit_card.transaction.pending_approval will give only pending approvals for this credit card == Skinny Controllers @cool.documents_authored_by(@john) @john.documents_tagged_with(@cool) @john.documents.tagged_with(@cool) == Named filters Normally you'd might just use the standard controller callbacks, such as before_crete and validate Litterature exmaple: Starting our with On that day vs. Michael killed himself Better way: before_create :make_created_now_if_created_today validate :ensure_balance_can_cover_amount_of_expense validate :amount_does_not_exceed_maximum_allowable_charge Wrap the conditions in predicates: def created_today? create_at.to_date == Date.today end == with_scope Let's you specify a scope of conditions that are used by everything inside the block Shouldn't abuse this for setting current user in scope, instead: @post = current_user.posts.find(params[:id]) with_scope is valid for certain conditions, TicketProxy @report.tickets.find(:all).map(&:apply_patch!)