This script enables you to launch your Rails application in production environment (port:80) with Nginx and Unicorn.
Please make sure that your Gemfile in your rails application includes unicorn.
| class BrandSweeper < ActionController::Caching::Sweeper | |
| observe Brand # Observers will introspect on the class, but Sweepers don't | |
| def after_update(brand) | |
| expire_action :controller => "brand", :action => :preview, :brand_id => brand.to_param | |
| end | |
| ... |
| module Cinch | |
| module Plugins | |
| class PluginManagement | |
| include Cinch::Plugin | |
| match(/plugin load (\S+)(?: (\S+))?/, method: :load_plugin) | |
| match(/plugin unload (\S+)/, method: :unload_plugin) | |
| match(/plugin reload (\S+)(?: (\S+))?/, method: :reload_plugin) | |
| match(/plugin set (\S+) (\S+) (.+)$/, method: :set_option) | |
| def load_plugin(m, plugin, mapping) |
| # 2. Include Sweeping module in your controller(s) to have cache_sweeper | |
| # method to be avaliable, or right in ApplicationController so it will be | |
| # available in all controllers inheriting from it. | |
| class ApplicationController < ActionController::Base | |
| include ActionController::Caching::Sweeping | |
| # ... | |
| end |
| template "/tmp/foo.rb" | |
| source "foo.rb.erb" | |
| cookbook "banana" | |
| end |
This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.
You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.
| class ApplicationController < ActionController::Base | |
| # ... | |
| unless Rails.application.config.consider_all_requests_local | |
| rescue_from Exception, with: lambda { |exception| render_error 500, exception } | |
| rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: lambda { |exception| render_error 404, exception } | |
| end | |
| private | |
| def render_error(status, exception) |
| #!/usr/bin/env ruby | |
| # List all keys stored in memcache. | |
| # Credit to Graham King at http://www.darkcoding.net/software/memcached-list-all-keys/ for the original article on how to get the data from memcache in the first place. | |
| require 'net/telnet' | |
| headings = %w(id expires bytes cache_key) | |
| rows = [] |
| DBQuery.prototype.p = function() { | |
| var args = arguments | |
| this.forEach(function(e) { | |
| var result = {} | |
| if(args.length == 0) { | |
| result = e | |
| } else { | |
| for(var i = 0; i < args.length; i++) { | |
| var target = e | |
| var keys = args[i].split('.') |
| var app = require('../app'); | |
| console.log(); | |
| app.routes.all().forEach(function(route){ | |
| console.log(' \033[90m%s \033[36m%s\033[0m', route.method.toUpperCase(), route.path); | |
| }); | |
| console.log(); | |
| process.exit(); |