Reputation: 9580
I come from a PHP and Python/GAE background and am new to RoR. Typically I'd have a global variable set up containing my unsecure and secure webpage's url, for use when templating. For example, if I want to link to an image, rather than saying img src="www.mysite.com/images/img1.png" I can use img src="{{ unsecure_url }}images/img1.png".
I'm thinking the best way to do this in RoR is to add the following to my application_helper. Is that valid?
def unsecure_url
"http://localhost:3000/"
end
def secure_url
"https://localhost:3000/"
end
And how can I switch between localhost and production, depending on whether I'm in a local environment or not?
Upvotes: 1
Views: 140
Reputation: 4311
If you use the pre-existing helpers, they should generate relative links for the current protocol and domain.
Take a look at link_to, and image_tag.
Upvotes: 1