0

In development, I would like to replace localhost:3000 to something like "domain.com:3000" or "domain.com". I can achieve this by adding alias to /etc/hosts file, for ex:

# /etc/hosts
127.0.0.1   domain.com

^^^ this one works, i can now view my site locally using domain.com.

The problem is that rails itself still uses localhost:3000, for example when generating urls via router methods. I feel that there should be some config for this.

2

2 Answers 2

4

You have to set:

Rails.application.routes.default_url_options[:host] = 'domain.com:3000'

in your development environment.

1

Custom domain name for your IP Address can be created. First of all find your IP Address using ifconfig. Then open /etc/hosts file with sudo.

/etc/hosts file is in readonly, so need to open with sudo

sudo vi /etc/hosts

There you will find at least two entries for 127.0.0.1 and 127.0.1.1, below this, create your own domain name

<IP_Address> domain.com

Save the file. Then start your rails server and bind with your IP Address.

rails s -b <IP_Address>

And you are done.

In browser, <IP_Address>:3000 will be same as domain.com:3000

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.