- Use database indexes to speed up queries. Rails only indexes primary keys, so you’ll have to find the spots that need more attention.
- Profile your code. The ruby-prof gem and plugin helped me make an application three times faster with only minimal changes to the code.
- Minimize graphic-related dependencies. If your application only needs to make a few thumbnails, don’t waste memory by importing large graphics libraries. Look at mini-magick or image_science for lightweight thumbnailing.
- Avoid excessive repeated rendering of small partials.
- Use CSS instead of inline tags to apply selective styling.
- Don’t use ActiveRecord’s
serialize
option to store large objects in database fields. - Use
attr_protected :fieldname
in models to keep database fields from being manipulated from forms (or from any calls toModel.update_attributes(params[:model])
). - Use Ruby classes and inheritance to refactor repeated controller code.
- Use unobtrusive Javascripting techniques to separate behavior from markup.
- Package self-sufficient classes and modules as plugins or RubyGems.
- Cache frequently accessed data and rendered content where possible.
- Write custom Test::Unit assertions or rSpec matchers to help with debugging test suite errors.
- Rotate the Rails and Mongrel logfiles using the
logrotate
daemon on Linux. - Build a reliable backup system.
- Automate deployment and maintenance with Capistrano or Vlad.
- Keep method bodies short. If a method is more than 10 lines long, it’s time to break it down and refactor.
- Run flog to determine overly complex methods and clases.
- Don’t use too many conditionals. Take advantage of
case
statements and Ruby objects to filter instead of multiply-nestedif
statements. - Don’t be too clever. Ruby has great metaprogramming features, but they are easy to overuse (such as
eval
andmethod_missing
). - Become familiar with the most popular plugins. Instead of re-implementing the wheel, save yourself some time by using well tested, popular plugins
You want Ruby? We can do it! Hire us for Ruby on Rails, CoffeeScript, BackBone.js, MongoDb, _underscore.js,dojo,Extjs,jQuery,Node.js,LAMP, AJAX info {at} rubyassist {dot} com
Wednesday, May 21, 2008
Rails Development Tips part-2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment