Archive for the 'rails' Category

Configuring ActionMailer to send email using Dreamhost

This is for all those dreamhosters out there. It took me a couple of tries to set up ActionMailer to send emails through my dreamhost account. Hopefully this will save someone some time. This is what I have in my environments/development.rb config file:

# ActionMailer settings for dreamhost
config.action_mailer.delivery_method = :smtp
config.action_mailer.server_settings = {
:domain => "mail.ankur.org",
:address => "mail.ankur.org",
:port => 25,
:user_name => "m0000000",
:password => "password",
:authentication => :login
}
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_charset = "utf-8"
The are two things to note.

1. your username is your mailbox name. This is that weird number that dreamhost generates for you and starts with an “m”

2. The domain and address had to be the same, and set to the outgoing mailserver, e.g. mail.yourserver.com. In theory, this should not have to be, but these are the settings that worked for me.

I lofe rails.

So I had a table called loves. The problem with naming a table loves is that rails will do this in the scaffolding:

“loves”.singularize

Guess what that is? Yes, the singular for loves is lofe. Don’t ask me what a lofe is, but I don’t lofe it. It turned out to be not such a big deal, because you can usually specify the :singular_name if you have to.
Btw, I am not creating a dating site. It’s more of a del.icio.us sort of love.

Routing the root of the site in rails

This is rails 101 but that’s the class I’m in right now. When you first set up rails, it generates an index.html file that responds to the root index of the application. So going to http://localhost:3001/ takes you to this index.html file. So how do you set up rails so that you can bind this default request to a controller? The index.html actually gives you some hints. Step 3 says:

Set up a default route and remove or rename this file. Routes are setup in config/routes.rb.

It’s a true statement but doesn’t say exactly how to do it. But routes.rb does:

# You can have the root of your site routed by hooking up ”
# — just remember to delete public/index.html.
# map.connect ”, :controller => “welcome”

I made it:

map.connect ”, :controller => ‘home’, :action => ‘index’