views:

105

answers:

4

Feel pretty dumb with this question.

In a Rails Model, I want to be able to find out the host and protocol. For example, if I am in a test environment it would return http://localhost:3000/ and if I was in production it would return something like http://my.application.com/?

Is this even possible?

Thanks!

jt

A: 

you can get full uri (http://localhost:3000/ or http://my.application.com/ etc) with request_uri

http://apidock.com/rails/ActionController/AbstractRequest/request_uri

fl00r
+2  A: 

You can get those values in your controllers (request.host, request.port etc.).

You'd have to give that to your models via parameters as the request object is only available in the controllers.

Maxem
A: 

See this Google Groups link; see also Making Session Data Available to Models in Ruby on Rails.

rlandster
This seems like an elegant approach (per the Making Session Data Available link) I am going to try that. Thanks.
Jonathan