baash05
baash05

Reputation: 4516

Getting the HOST/URL of a Ruby on Rails app? Extended

I have read the other question with the same title and it doesn't in fact get the URL of the app. It gets the URL of the current page, which is mighty close, and suited the needs of the question perfectly. Sadly I don't have a current page, or even a controller.

I want to get the HOST/URL of the app. From within a worker DYNO.

I have two "apps" on Heroku right now... one testing and one production. Well technically both are production, one is beta, the other is released.

I would like to be able to figure out the URL of the app, because I send out data to a third party and I'd like to include a link back to the system (and a specific record)...

More detail:
I have a WORKER send an XML file contain product details to eBay. In the product details there's space for an HTML compatible "description".. I want to have a link back to my system in there, so a viewer can see details that exceed eBay's ability to display. Thus I need the URL of my system.

Upvotes: 1

Views: 1784

Answers (2)

j_mcnally
j_mcnally

Reputation: 6958

There is nothing in ENV / config but you could add it with:

heroku config:add HOST=warmmist837.herokuapp.com

or better yet

heroku config:add BETA=1

then in code you can say ENV['HOST'] or ENV['BETA']

Typically in rails code i would say Request.host but i don't think that will help as you are in a worker not a Rack request.

also if you are worried about working locally with this setup, if you are using RVM as your probably should be you can add the export statement to the .rvmrc

export HOST=my.localmachine.com

Upvotes: 1

Ryan Bigg
Ryan Bigg

Reputation: 107718

You can get to the Rails application's routing helpers using this method:

Rails.application.routes.url_helpers

To access a helper from this module, just call the method on it and pass it a host:

Rails.application.routes.url_helpers.products_url(:host => "example.com")

Upvotes: 6

Related Questions