A gem to help you document your Rails ActiveRecord model

I’ve been using the “annotate” gem for a while and it’s simple whilst incredibly useful. Essentially once run it documents each resource in your database within the appropriate file. Here’s how to get it working. Step 1 Install the gem. There are a few ways to do this but I usually include the following line in my Gemfile: [code language=”ruby”] gem ‘annotate’ [/code] Then run “bundle install” from the command line. Step 2 Generate the schema annotations by running: [code language=”bash”] annotate [/code] in the root of your rails project directory and it will inject the schema details for each “table” into the respective “model.rb” file e.g. “user.rb” might contain: [code language=”ruby”] # == Schema Information # # Table name: users # # id :integer not null, primary key # screen_name :string(255) # name :string(255) # created_at :datetime # updated_at :datetime # [/code]

Ruby, Rails & RVM woes

I’ve had several issues over the past day pertaining to Ruby, Rails and RVM and all of them were caused by one silly thing. Problem 1: You can’t swap between Ruby versions using RVM If you can’t swap between Ruby versions that you know you’ve installed then you’ve probably installed something using “sudo”. It is highly recommended that you install & use RVM in the single user mode as this is easiest. If you do this then all the versions of Ruby etc. that you install will be installed in your home directory (usually ~/.rvm/) instead of system wide and this negates a whole bunch of complexities. Running this command will tell you which ruby executable you’re using: [code language=”bash”] which ruby [/code] If the executable is not sitting in your home directory e.g. it’s in /usr/local/bin then you’re in a spot of bother. The easiest way I’ve found to …

Read more