Rails 3: Render Production Errors in 1 Controller

We want to see errors in production only for our admin controllers.
In Rails 2 this was simple, but now we had to get hacky:

class AdminController < ApplicationController
  rescue_from Exception, :with => :render_simple_error if Rails.env.production?
  def render_simple_error(e)
    render :text => "#{e.message} -- #{e.class}<br/>#{e.backtrace.join("<br/>")}"
  end
end

Its not very pretty (session/params are missing), but solves our pain for now.

Installing MySql Handlersocket in Ubuntu Natty for Ruby

Install

sudo apt-get install mysql-server -y;
sudo apt-get install handlersocket-doc -y;
sudo apt-get install handlersocket-mysql-5.1 -y;
sudo apt-get install libhsclient-dev -y;

Configure

#/etc/mysql/my.cnf -- under mysqld section
loose_handlersocket_port = 9998
loose_handlersocket_port_wr = 9999
loose_handlersocket_threads = 16
loose_handlersocket_threads_wr = 1
open_files_limit = 65535 

Start

mysql -e "install plugin handlersocket soname 'handlersocket.so';"
sudo /etc/init.d/mysql restart

# should show lots of handlersocket processes
mysql -e "show processlist;"

Use

gem install handlersocket

require 'handlersocket'
h = HandlerSocket.new(:host => '127.0.0.1', :port => '9998')

# open PRIMARY index on widgets.user table, assign it ID #1
h.open_index(1, 'widgets', 'user', 'PRIMARY', 'user_name,user_email,created')
...

more of this can be found at ruby handlersocket introduction and ActiveRecord Handlersocket gem

Updating to Rails 2.3.11 without using html_safe

Only thing not working as expected is that the h helper did escape html_safe output, but we can fix that easily…

# make h work the same no matter if a string is safe
# ERB::Util.h("
".html_safe).should_not == "
" module ERB::Util def html_escape(s) s.to_s.gsub(/[&"><]/) { |special| HTML_ESCAPE[special] } end alias h html_escape module_function :h module_function :html_escape end