Thursday, February 26, 2009

Errno::ECONNREFUSED: Connection refused - connect(2)

Errno::ECONNREFUSED: Connection refused - connect(2)

If you get this error, one of the reason could be incorrect or no ActionMailer settings. The following structure needs to be present in your production.rb (or whatever config file):

ActionMailer::Base.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'mydomain.com',
:authentication => :plain,
:user_name => 'user@mydomain.com',
:password => 'password'
}

Tuesday, February 17, 2009

Using define_method to create a method that takes arguments

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/211436
http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/211440

Example:

Setting.all.each do |setting|
define_method setting.name do |*a|
r = find(:first, :include => :setting, :conditions => ["setting_id = ?", setting.id])
full_record = (a.length == 0) ? false : a[0]
full_record ? r : r.value
end
end