edgecase's ruby_koans at master - GitHub
The Ruby Koans walk you along the path to enlightenment in order to learn Ruby. The goal is to learn the Ruby language, syntax, structure, and some common functions and libraries. We also teach you culture. Testing is not just something we pay lip service to, but something we live. It is essential in your quest to learn and do great things in the language.
Font Squirrel | Download Hundreds of Free @font-face Fonts
Download hundreds of prepackaged @font-face kits
datagraph's rack-throttle at master - GitHub
Rack middleware for rate-limiting incoming HTTP requests.
Intridea Blog: REST isn't what you think it is, and that's OK
Pretty much everyone who claims to have a REST API, in fact, does not. The closest I’ve found is the Sun Cloud API which actually defines a number of custom media types for resources and is discoverable based on a single known end-point. Everyone else, thanks for playing.
Localized external services - GIANT ROBOTS SMASHING INTO OTHER GIANT ROBOTS
ShamRack mounts a Rack app locally, just for your tests. It goes one further: it “mounts” it using Net::HTTP such that requests to the Rack app never hit any network.
Copy a Paperclip attachment to another record
Just assign the existing attachment to another record:
new_photo = Photo.new
new_photo.image = old_photo.image
Paperclip will duplicate the file when saving.
To use this in forms, pimp your attachment container like this:
class Photo < ActiveRecord::Base
has_attached_file :image
attr_accessor :copy_of
def image_url
if copy_of
copy_of.url
else
image.url
end
end
end
And in the controller do:
new_photo = Photo.new(:copy_of => old_photo)
Force absolute URLs in views throughout a response
This is more tricky than it should be because url_for
, asset_path
, etc. all rely on different mechanisms.
Anyway, you can use the attached trait like this:
class ExampleController < ApplicationController
does 'host_enforcement', :for => 'some_action'
end
Short explanation:
-
asset_host
is used for links to stylesheets and javascripts -
asset_host
belongs toActionController::Base
-- changes are persistent and will not be reset after a request -
rewrite_options
is used by the..._path
methods in the views
^...