I’ve been working on an application that sends emails. (You’ll hear more about the application very soon) The emails often contains links to the application. In development and test I want these links to point to localhost:3000, and in production I want them to point to mydomainname.com. Therefore, the ActionMailer class needs to know the root of the application.
So, in environment.rb I added the following line:
1
| |
And in production.rb I added the following line:
1
| |
Unfortunately, when I deployed to production the emails were being sent with http://localhost:3000 as the base for links.
I checked my mongrel config and everything seemed to be set up right for production. I checked the logs and saw that the application was running as production.
Then I ran script/console production, saw the following error message, and immediately got an idea what I did wrong.
1
| |
APPLICATION_ROOT was still returning ‘http://localhost:3000’
The problem was I was counting on settings in production.rb to override those in environment.rb. And they do except I defined my setting as a CONSTANT.
I moved the constant declaration out of the environment.rb and into both development.rb and test.rb and everything now works fine.
The thing I still don’t understand is that according to page 330 of the PickAxe Ruby is supposed to allow you to alter the value of a constant.
Anyone know why the constant’s value didn’t change in my config files?