DEV Community

Ian
Ian

Posted on

1 1

Add multiple subdomains to your rails 7 app.

Subdomains are a great way to organize different parts of your app. You might have an api subdomain, news subdomain, etc.

routes.rb



constraints subdomain: 'my-subdomain' do
  # add routes
end


Enter fullscreen mode Exit fullscreen mode

development.rb

Add new hosts to your development.rb configuration.



config.hosts << "my-subdomain.my-domain.local"


Enter fullscreen mode Exit fullscreen mode

Development Environment

Add development subdomain(s) to your /etc/hosts file so it routes to your development server



127.0.0.1 my-subdomain.my-domain.local


Enter fullscreen mode Exit fullscreen mode

Don't forget to add port 3000! You'll go this url in your browser. my-subdomain.my-domain.local:3000

Heroku

Image description

DNS Configuration

Add a CNAME record for each subdomain in your DNS configuration.

Use the domain name and DNS Target from Heroku.

That's it! You should be good to go.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read full post →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

đź‘‹ Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay