Highlight your prompt on production machines
Next in our series on not shooting yourself in the foot: Doing a sudo shutdown -h now on the main database server right before you head home to cook dinner for six.
eliotsykes's asset_fingerprint at master - GitHub
Asset Fingerprint Plugin for Ruby on Rails - allows you to use md5 or timestamps in query string or in asset filenames as suggested by Google Page Speed
jnicklas's carrierwave at master - GitHub
File upload solution that supports form roundtrips when a validation fails.
Lessons learned from 13 failed software products « Successful Software
I asked other software entrepreneurs to share their stories of failure in the hope that we might save others from making the same mistakes. To my surprise I got excellent 12 responses, which I include below along with one of my own. It is a small sample and biased by self selection, but I think it contains a lot of useful insights.
Netty - the Java NIO Client Server Socket Framework - JBoss Community
The Netty project is an effort to provide an asynchronous event-driven network application framework and tools for rapid development of maintainable high performance & high scalability protocol servers & clients.
Insertion/Deletion callbacks
All ActiveRecord associations except for has_many :through support callbacks for pre- and post-insertion/deletion via the following, self-documenting parameters:
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_hostis used for links to stylesheets and javascripts -
asset_hostbelongs toActionController::Base-- changes are persistent and will not be reset after a request -
rewrite_optionsis used by the..._pathmethods in the views
^...
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...