Skip to content

Instantly share code, notes, and snippets.

MVIM Cheat Sheet:
* auto complete
ctrl+n
or
ctrl+p
* Running Rake for test
:Rake
# Rails 3 generator for miniskirt
# Add the factory_girl gem
append_file 'Gemfile', <<-GEMS
group :test do
gem 'miniskirt'
end
GEMS
# touch the file for storing factories
gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
class ImageMagick
def self.palette(image_file, number_of_colours = 5)
image_details = %x(convert #{image_file} +dither -depth 8 -colors #{number_of_colours} -unique-colors txt:-)
image_details.scan(/#[a-z0-9]{6}/i)
end
end
# Factory girl, relaxed.
#
# Factory.define :user do |f|
# f.login 'johndoe%d' # Sequence.
# f.email '%{login}@example.com' # Interpolate.
# f.password f.password_confirmation('foobar') # Chain.
# end
#
# Factory.define :post do |f|
# f.user { Factory :user } # Blocks, if you must.
### Basic routes ###
Rails 2:
# singular resource
map.resource :account
# resources with addition member & collection actions
map.resources :games, :member => { :download => :get }, :collection => { :favourites => :get }
Rails 3: