I'm creating a Reddit sort of site to learn Rails but I'm using subdomains instead of longer URLs for subreddits (ie funny.reddit.com instead of reddit.com/r/funny).
For development, I'm using http://vcap.me (redirects to localhost) to work with subdomains as I think plain localhost doesn't work with subdomains.
I'm having some difficulties linking to these subdomains. I can do
subreddit_url = url_for(host: "http://vcap.me", subdomain: subreddit.subdomain)
and works just fine. However, I don't want to hardcode the host since I want to eventually push to Heroku and the host will be different. I tried doing something similar to How do I set default host for url helpers in rails?, more specifically
class ApplicationController < ActionController::Base
def default_url_options
if Rails.env.development?
{:host => "http://vcap.me"}
else
{}
end
end
end
but my url_for returns '/' when I do
url_for(subdomain: subreddit.subdomain)
I've also tried setting only_path: false but it also doesn't do anything.
Using Rails 4.2 Ruby 2.2.
Thanks!