own application configuration

./config/my_configuration.yml
MyConfig:
  username: my_username
  password: my_password
  host: my_host

be sure to enter spaces, NOT tabs

./config/environment.rb
require 'ostruct'
require 'yaml'

OwnConfigFile = "#{RAILS_ROOT}/config/my_configuration.yml"
if File.exist?(MyConfigFile)
  ::ApplicationConfig = OpenStruct.new(YAML.load_file(MyConfigFile))
end

in application:

config = ApplicationConfig.MyConfig;
puts config['username']

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