[1,2,3,4].sample # => e.g. 4 If you'd like to cheat and give different weights to each element...
When you use one line Ruby comments in ERB templates you should never do this (notice the whitespace in front...
Seems like a useful gem for cases where ActiveRecord is overkill but you don't want to do everything by...
To use different Ruby versions on your computer you can use the Ruby Version Manager. It also allows you to...
require 'open-uri' File.open('/target/path/to/downloaded.file', "wb") do |file| file.write open('http://example.com/your.file').read end Basic Authentication
There are several options, but most of them are impractical. The best way is to use the :ruby filter:
Note: This applies specifically to MySQL. In PostgreSQL for example, this is not an issue. If you care about performance...
By default, Rails views escape HTML in any strings you insert. If you want to insert HTML verbatim, you need...
While 2.0 will include a number of syntax changes, new features and general improvements, mentioned below, it is anticipated to...
The most common use case for Ruby's #collect is to call a method on each list element and collect...
In order to monitor a Rake task using God your Rake file must write a file with its process ID...
When you require the Ruby debugger to be available from your Rails console (e.g. you want to inspect a method...
Oniguruma is an advanced regular expression engine for Ruby. Install Oniguruma with binary dependencies like this: sudo apt-get install...
The technique described in this card has an important caveat: The result of GROUP_CONCAT is truncated to the maximum...
You can use heredoc to avoid endlessly long lines of code that nobody can read. Heredoc strings preserve linebreaks and...
If Rails or Rake are complaining about a missing gem that is listed in your Gemfile.lock and the listed version...
Sometimes you want to use a vanilla Ruby method like a block. You can use Object#method to obtain a...
ExecJS lets you run JavaScript code from Ruby. It automatically picks the best runtime available to evaluate your JavaScript program...
The state_machine gem comes with a rake task that lets you generate PNG graphs from any model using state...
class Errormaster CoffeeIsOut = Class.new(StandardError) # is prettier than class CoffeeIsOut < StandardError; end end Reference such an error class with Errormaster...
Grit gives you object oriented read/write access to Git repositories via Ruby.
jQuery as new default Javascript library, streaming response support, attr_accessible with roles, prepared statements, easier migrations.
If you have a time given in a different time zone than your local one, parsing will convert it for...
I believe that when WEBrick has trouble bringing up your Rails application, the WEBrick component that is supposed to print...