■Use a “test rig” file to generate standard CRUD tests.
■Use helper methods in tests and in views to keep your code at a consistent level of abstraction.
■Consider test/spec, which provides a BDD (behavior-driven development) layer on top of test/unit. I prefer this to rspec.
■Consider using simple Ruby hashes instead of fixtures.
■If you’re using the default resource scaffold, which allows xml access to models, override to_xml in the model so you can use the :except option to keep sensitive fields from getting included.
■Don’t bother with small RJS files; just put the RJS code in the controller.
■All the respond_to code and XML handling in the scaffold resource controller is not necessarily a good thing. I don’t use respond_to unless I know I’ll be providing API access. It adds noise to your code, can be a security hole, and just isn’t needed if you aren’t supporting an API.
■If you accept credit cards, be sure not to store them in your database. VISA’s rules are hard to comply with, and penalties for non-conformance are high. Use a solution that allows you to immediately pass the credit card to the gateway, or even better, post the form with the credit card info directly to the gateway. Braintree Payment Solutions allows you to do recurring payments without storing credit cards by returning a token that you can use for future charges.
■make_resourceful plugin automates creation of CRUD actions for a resource.
■In most cases, has_many :through is a better solution than has_and_belongs_to_many. One time the habtm approach makes sense is for tagging.
■You can define methods on an association proxy. In the model, e.g., has_many :visits do <define custom find here> end.
■ferret is a port of the lucene search engine, whereas solr uses the original Java source, so it is more current—but it does require that you run a Java app server for the engine.
■If almost all of a page can be cached, but a little part like the login name cannot, cache the entire page and then use JavaScript to replace that section of the page after it loads.
■Disable sessions for controllers or actions within a controller where they aren’t needed.
■To decode the contents of a session: Marshal.load(File.read(“tmp/sessions/filename”)).
■use pp (pretty print) to print out an object in more readable form (much nicer than p(object) or object.inspect).
■simply_helpful is rolled into Rails 2.0. The plugin is now in the legacy folder. If you use this in your 1.2.x apps they’ll have a smooth path to 2.0.