New Rails Project Best Practices
March 3rd, 2010Every now and again, our team creates a new Rails app.
The last time we did this, we had a discussion about how we could make our new Rails app easier to maintain and test, as well as reducing the duplication across multiple Rails apps.
Here’s the list of recommendations we came up with:
Cucumber Feature Tests
- Don’t change generated step definition files (e.g. web_steps.rb from webrat), instead add new steps to new files.
- Extract common steps (ones used in more than one project) to a template
WebMock
Template
- Use a template for common stuff such as Capistrano Tasks, Rake Tasks, Scripts and Cucumber Step Definitions – as well as the usual initial project setup
Configuration
- Instead of using constants in production.rb, use a configuration class.
Continuous Integration
- Have tests that test installing from scratch
- Have tests that test upgrades
- Have a test that uses the latest versions of gems
(you can never have too many tests).
Deployment
- Use git-deploy instead of just capistrano – it’s faster, easier, and uses the power of git
REST
- Use Restfulie
Why?
August 20th, 2009It is with great sadness that I see _why has gone missing.
I’m a great admirer of his many works, including Shoes (a great GUI framework), Hpricot (my HTML parser of choice), HacketyHack (a great way for kids to learn programming), TryRuby (a way to try Ruby in your Web Browser), and of course his Poignant Guide to Ruby.
Why’s Poignant Guide to Ruby was the first Ruby tutorial that I read. I liked its unique style and narrative that, for me at least, introduced Ruby concepts in a memorable way, particularly Dwemthy’s Array (see chapter 6) which introduced me to metaprogramming and DSLs in Ruby.
You can still see the full Poignant Guide to Ruby, with all the great illustrations, and you can still purchase the book from lulu.
Due to the nature of github, his code lives on in forks of his projects.
Please, let us all #clapwithwhy, and I hope he comes back to enrich the Ruby community with his creative genius.
Back to a Mac
July 28th, 2009I’ve recently switched back to using a Mac after many years using Ubuntu.
I much prefer OS X to Ubuntu, mainly because some of the software it has is not available on Linux, such as iTunes, and TomTomHome.
What surprised me is how many essential applications and functions were missing from OS X (10.5.7), when compared to a default install of Ubuntu (9.04).
Here’s the list of essential software to bring OS X to the same level as Ubuntu 9.04:
- Adium multi-protocol chat client
- Growl desktop notifications
- MenuCalendarClock a better menu bar calendar
- GoogleNotifier gmail notifier for the menu bar
- iStat menus System resource graphs for the menu bar
- Transmission BitTorrent client
- VLC a video player that plays anything (almost)
- RealPlayer because VLC can’t play some RealPlayer content
- OpenOffice because Microsoft Office is too expensive
Whilst installing all this software, I noticed what a pain it was, compared to the simple ‘apt’ or Synaptic in Ubuntu. If only there was a package management system for OS X that would allow me to install all the software I want.
On top of the essential software above, I installed the following, to get me to my minimum machine specification:
- Tweetie Twitter client
- FruitMenu allows you to customise your Apple menu
- Firefox because Safari just doesn’t cut it
- MacVIM for editing code
- Netbeans for Java ME development
- Mpowerplayer SDK because Sun don’t produce an OS X version of the Java ME tools themselves
- Rubymine for Ruby development
- Git source control
- gitx superior gitk/git-gui clone for OS X
- FFXporter Free Flickr eXporter iPhoto plugin
- ffmpegx for all your video conversion needs
- Fugu SFTP/SCP client
- Facebook Exporter for iPhoto
If I ever need to rebuild this Mac, it’s going to be a real pain downloading and installing all those applications again.
Offline Gem Server
July 8th, 2009I’ve had an offline gem documentation server installed for a while on my machine, after following Jason Seifer’s instructions.
Recently, however, when I installed new gems I got the following error:
invalid argument: –fmt=html
This is, I think, because the hanna gem that provides the rdoc template needs to use a html output formatter, which seems to have disappeared from newer versions of rdoc.
As a solution, I’ve switched to the sdoc gem, which I think has a better rdoc template than hanna.
The full install instructions for my offline gem documentation server are:
- Install pre-requisites: Apache and Phusion Passenger – also add gems.github.com to your gem sources
- Install sdoc gem – this provides the rdoc template, that puts a search box on each rdoc page to allow you to search the methods and classes of a gem:
sudo gem install voloko-sdoc
- Edit your ~/.gemrc file, to add the correct options for sdoc, and (optionally) stop ri docs being generated:
gem: --no-ri rdoc: --inline-source --line-numbers --fmt=shtml --template=direct
- Regenerate all your rdocs so they all use the new sdoc template:
sudo gem rdoc --all --no-ri
- Install the sinatra-rubygems gem, to allow your gem rdocs to be served by passenger installed on your local machine:
sudo gem install jnewland-sinatra-rubygems
- Add the following to your /etc/hosts file:
127.0.0.1 gems.local
- Add the following to your apache passenger config – customizing the DocumentRoot and Log locations as required:
<VirtualHost *:80> DocumentRoot "/opt/sinatra-rubygems/public" ServerName gems.local:80 ErrorLog /var/log/apache2/gems-error_log CustomLog /var/log/apache2/gems-access_log common </VirtualHost>
- After restarting apache, you should then be able to visit gems.local