Why I won't help you - Gem Session
But then there are those posts where the author pastes 10 pages of confused code with no context whatsoever and then demands to know why they're getting funny errors. I find this sort of behaviour offensive to all the people who are basically dealing out free support. I'd rather spend my time helping people who actually give a damn.
jnicklas's carrierwave at master - GitHub
File upload solution that supports form roundtrips when a validation fails.
A tracer utility in 2kb « JavaScript, JavaScript
Inspired by a snippet of code in Oliver Steele’s legendary Functional library, here’s a lightweight tool to help keep track of JavaScript invocations. It works in Chrome, Safari, Firebug and IE8.
wkhtmltopdf - Project Hosting on Google Code
Simple shell utility to convert html to pdf using the webkit rendering engine, and qt.
Less.js Will Obsolete CSS
Less.js is a JavaScript implementation of LESS that’s run by your web browser. As any JavaScript, you include a link to the script in your HTML, and…that’s that. LESS is now going to process LESS code so instead of including a link to a CSS file, you’ll include a link directly to your LESS code. That’s right, no CSS pre-processing, LESS will handle it live.
thoughtbot's bourne at master - GitHub
Test spies are a form of test double that preserves the normal four-phase unit
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)
Unobtrusive JavaScript and AJAX
Attached (see below) is some code to allow using unobtrusive JavaScript on pages fetched with an AJAX call.
After you included it, you now do not use the usual
$(function() {
$('.some_tag').activateStuff();
});
any more, but instead you write
$.unobtrusive(function() {
$(this).find('.some_tag').activateStuff();
});
that is
-
$.unobtrusive()
instead of$()
- don't do stuff to the whole page, but just to elements nested below
$(this)
Normal pages work as before (your $.unobtrusive
functions are ca...