Skip to content

Instantly share code, notes, and snippets.

@dignoe
dignoe / after_restart.rb
Created March 8, 2017 23:13
Automatic maintenance page on migrate with AWS OpsWorks + Rails
# Disable maintenance page
Chef::Log.info("Disabling maintenance page")
file "/srv/www/your_app/shared/system/maintenance.html" do
action :delete
end
@dignoe
dignoe / will_paginate_helper.rb
Last active September 7, 2016 18:39
Add rel="next" & rel="prev" to will_paginate gem (with custom paths)
# config/initializers/will_paginate_helper.rb
# Tested with will_paginate v3.0.7
module WillPaginate
module ActionView
class LinkRenderer < ViewHelpers::LinkRenderer
include ListingHelper
protected
def url(page)
@dignoe
dignoe / gist:3989505
Created October 31, 2012 20:10
Redirect all domains to specified domain in Rails 3
MyApp::Application.routes.draw do
if Rails.env.production?
constraints(:host => /^(?!www\.my-domain\.com)/) do
match "(*path)" => redirect { |params, request| URI.parse(request.url).tap { |x| x.host = "www.my-domain.com" }.to_s}
end
end
end
@dignoe
dignoe / gist:2485272
Created April 25, 2012 01:33
Patch to get content_for working with action caching and fragment caching in Rails 3.1
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?