Skip to content

Instantly share code, notes, and snippets.

@debprado
debprado / en.yml
Created January 6, 2012 01:30 — forked from chrisbloom7/README.md
A cheap knock off of the default validates_length_of validator, but checks the filesize of a Carrierwave attachment
# config/locales/en.yml
en:
errors:
messages:
wrong_size: "is the wrong size (should be %{file_size})"
size_too_small: "is too small (should be at least %{file_size})"
size_too_big: "is too big (should be at most %{file_size})"
@debprado
debprado / rails.history.js
Created January 3, 2012 19:04 — forked from nragaz/rails.history.js
Add callbacks to remote links in Rails to manage browser history using pageState and replaceState
function historySupport() {
return !!(window.history && window.history.pushState !== undefined);
}
function pushPageState(state, title, href) {
if (historySupport()) {
history.pushState(state, title, href);
}
}
@debprado
debprado / factories.rb
Created August 3, 2011 19:52 — forked from anonymous/factories.rb
factory attachment rails 3
Factory.define :item do |f|
include ActionDispatch::TestProcess
f.name "Macbook Pro 15"
f.price_in_dollars 1500
f.photo fixture_file_upload('/files/avatar.jpg', 'image/jpg')
end
@debprado
debprado / gist:1115635
Created July 30, 2011 15:23
Fix attachment_fu in rails 3
def temp_path
p = temp_paths.first
if p.is_a?(ActionDispatch::Http::UploadedFile) # Rails 3.0.3 compatability fix
p.tempfile.path
else
p.respond_to?(:path) ? p.path : p.to_s
end
end
class FooSweeper < ModelOnlySweeper
observe Foo
def after_save(object)
expire_cache_for(object)
end
def after_destroy(object)
expire_cache_for(object)
Factory.define :application do |factory|
factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
end