Archive for the ‘rails’ tag
Rails Constants: Location matters
Rails framework provides a standard location for defining application specific constants. All default constants go in constant/environment.rb and any environment specific overrides go in config/environments/<env>.rb file. Normally, any constant that is overridden in environment specific file takes precedence. However, there is a catch. If a constant is defined outside of Rails::Initializer.run block then it overrides all other definition preceding it.
Hence, when defining constants in default config/environment.rb file, beware:
require File.join(File.dirname(__FILE__), 'boot') Rails::Initializer.run do |config| A_CONSTANT = "value" end # Do not define environment specific constants here.
Enjoy!
ActionMailer, GMail and TLS
Prior to rails 2.3.2, if you needed to use GMail as your SMTP carrier (sending out emails from your app), you had to use one of the following plugins to modify the ActionMailer::Base class to support TLS for ActiveRecord.
- tlsmail
- ambethia-smtp-tls
- openrain-action_mailer_tls
- simplificator-tls-support
In rails 2.3.2, this is supported natively, provided you had proper configuration specified:
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:enable_starttls_auto => true,
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'localhost.localdomain',
:authentication => :plain,
:user_name => "username",
:password => "password"
}
This should work without any plugins/gems in rails 2.3.2. The only caveat is that ruby version has to be >= 1.8.7. It won’t work with ruby 1.8.6 or older, as documented here.
Enjoy!
Installing passenger/mod_rails on CentOS
Installing passenger/mod_rails on CentOS sometimes is not as simple as:
$ gem install passenger
and
$ passenger-install-apache2-module
In my case, I also had to install “apr-util-devel” yup package. Also, for some reason the “sudo yum install
$ sudo su -
$ yum install apr-util-devel
After this, “gem install passenger” and passenger-apache module install worked fine.
Installing mysql gem on CentOS
Installing mysql gem on cent-os may sometimes be not as easy as:
$ gem install mysql
It may result in compilation error and fail to install. While this may happen for various reasons, in my case, I had to install “mysql-devel” package.
$ sudo yum install mysql-devel
Once I did this, the mysql gem installed happily.