Forum: Ruby on Rails Setting constants based on TLD

Posted by Ben Densmore (bdensmore)
on 2013-01-24 20:01
(Received via mailing list)
Our app currently has some constants set in the environment.rb file 
using
Object.const_set "ProductionDomain", "mydomain.com" and some other 
domain
related constants that are based off of this initial constant.

We are now going to be offering a .fr domain in addition to .com so I 
need
to make these constants dynamic based on which TLD a person may be on.

My thought was that maybe I should move these constants into their own 
file
in the initializers folder and can then check whether the user is on the
.com TLD or .fr

Is there a better way to handle this? I couldn't find a way to do it in 
the
environment.rb file so I'm thinking this other approach may be the way 
to
go.

We are on Rails 2.3.14, so any options need to be compatible with that
version.

Thank you,
Ben
Posted by "Андрей Большов" <asnow.dev@gmail.com> (Guest)
on 2013-01-24 22:44
(Received via mailing list)
Do not undesten what's the reason to have such constants. Site users 
send
there requests with domain name and you can get it in "request.host" or
other ActionController 
<http://apidock.com/rails/ActionController>::Reques...
 methods.
If you needed dynamical behavior then you should refuse constants and 
use
methods or variables.

, 24  2013 ., 23:00:19 UTC+4  Ben Densmore
:
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.