Mon, 09 Jul 2007
Exception handling
./lib/mymodule.rb
module MyModule

  class Error < RuntimeError; end
  class ConnectionError < Error; end

  def connect
    
    if something_failed?
      raise ConnectionError, "connection failed due to..."
    end
  end
end
somewhere in controller
  include MyModule

  def do_connect
    begin
      connect
    rescue MyModule::ConnectionError => err
      flash.now[:notice] => err
    end
  end

(posted at 01:15 | filed under programming/rails | link)    (comments | add new)