AnApprentice
AnApprentice

Reputation: 110950

how to output the current protocol and url using rails?

I have a share dialog.

On dev it looks like:

http://xxxxxx.com/stuff

On prod:

https://yyyyyyyyyyy.com/stuff

What's the best rails way to output #Protocol# #URL#

And where can I set these in rails? thanks

Upvotes: 13

Views: 14304

Answers (4)

Abhi
Abhi

Reputation: 3611

Try adding the following to your development.rb file

Rails.application.routes.default_url_options[:protocol] = 'http'

and in production.rb file

Rails.application.routes.default_url_options[:protocol] = 'https'

Upvotes: 2

Artem P
Artem P

Reputation: 5333

Best way I found:

url_for(:only_path => false)

Upvotes: 0

Kyle Heironimus
Kyle Heironimus

Reputation: 8041

request.protocol
request.url

See the request object.

Upvotes: 30

Anatoly
Anatoly

Reputation: 15530

request object. you can use request.fullpath

API reference is here

Upvotes: 2

Related Questions