Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6348829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:29:56+00:00 2026-05-24T21:29:56+00:00

In Rails 2.3, I could just use HOST to get my hostname but it

  • 0

In Rails 2.3, I could just use HOST to get my hostname but it seems it’s not available anymore. What can I use instead?

I just want something that returns localhost:xxxx (with real port number) when I run the code from my machine, and http://www.mysite.com when I run it in production.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:29:57+00:00Added an answer on May 24, 2026 at 9:29 pm

    You have several options:

    • call system’s hostname command (assuming it’s *nix): `hostname`
    • use the socket gem:

      require 'socket'

      Socket.gethostname

    • in case you just want to know the current domain the request visits: request.domain

    Update

    From the request object, we can fetch both the host and the port, please check out these methods:

    • request.protocol
    • request.host
    • request.port

    You could build the full url from these methods.

    From my personal experience, for most projects you might have a fixed domain for each environment, and usually configure that in a yaml file or so (for example, to send email and use urls with domain name in the email body, we usually read the config and set options for url helper). So I usually just read the current environment’s urls configuration and use them from the code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I could just use a find_by_sql to accomplish this, but I'd like to do
I am trying to use select2 with my rails application but cannot get the
I could test upload of one file attach_file 'photo', File.join(Rails.root, 'public', 'uploads', 'test.png') But
I am using Ruby on Rails, but I think this question could be applied
I'm writing my first rails plugin and could use a little help. In a
I've just updated to Rails 2.3.11. In an earlier version I could write the
I am a beginner in Rails. I use 2.3.X. I just saw Rails 3
I'm trying to use rails 3 without any db backend, but it still insists
I just installed Postgres.app for mac to use with local rails development. Installation was
I just started learning to use Sunspot / Solr with Rails. I followed this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.