Reputation: 1714
So I want to create subdomains for mysite.com, such as forum.mysite.com, blog.mysite.com, podcast.mysite.com, etc.
We're a teaching site, so any posts we create will link to a relevant informative video that covers the post topics in more depth. I also want these subdomains to reference all main site user data when a user is signed in. So for example, when signed in on forum.mysite.com, I can display the user's achievements on the forum posts (that they've earned through the main site).
For these reasons, among others, I want the subdomains to reference the same database as the main app. I've been told that when creating a subdomain, one should use a separate app. However, I figured this is a case where I should use the same app and just wire up the routes accordingly, as outlined in this post.
This line in my routes.rb file (basically taken straight from the source) makes it easy to link the subdomain to my blog index:
match '/', to: 'blog_posts#index', constraints: { subdomain: 'blog' }, via: [:get, :post, :put, :patch, :delete]
However, when I use this method, I'm able to go to routes like blog.mysite.com/videos/28, which is weird, because I only want videos accessible via the main site. So blog.mysite.com/videos/28 should render a 404.
I'm quite new to hooking up subdomains, so I'm not sure which way to go at this would be best. Is there an easy way to just create multiple applications that link to the same database? If so, are there any repercussions? Or would it be best to just use the same application, and do massive tweaking to the routes?
I'm using Heroku for hosting, so that's where my database lives.
Upvotes: 0
Views: 65
Reputation: 2365
It looks like you have a resources :videos
in there somewhere, so you'll need to add the subdomain constraint there.
Basically, define subdomains for every route and resource.
Upvotes: 1