Skip to content

Instantly share code, notes, and snippets.

@debprado
debprado / en.yml
Created Jan 6, 2012 — forked from chrisbloom7/README.md
A cheap knock off of the default validates_length_of validator, but checks the filesize of a Carrierwave attachment
View en.yml
# 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 Jan 3, 2012 — forked from nragaz/rails.history.js
Add callbacks to remote links in Rails to manage browser history using pageState and replaceState
View rails.history.js
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 Aug 3, 2011 — forked from anonymous/factories.rb
factory attachment rails 3
View factories.rb
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 Jul 30, 2011
Fix attachment_fu in rails 3
View gist:1115635
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
View foo_sweeper.rb
class FooSweeper < ModelOnlySweeper
observe Foo
def after_save(object)
expire_cache_for(object)
end
def after_destroy(object)
expire_cache_for(object)
View factories.rb
Factory.define :application do |factory|
factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
end