Ruby on Rails – How to Get Current URL

cross-domainruby-on-rails

I'm trying to get the current URL in Rails using request.host, request.url but I have a website that is in 2 domains, so:

When I'm at www.example1.com the request.host or .url show www.example1.com

When I'm at www.example2.com the request.host or .url shows example1.com
because the example2 is getting all content from example1 and showing it in the example2(parsed)

So the request.host gives me the host, and request.url seems to be giving me the host also
What I need is the URL that appears in the browser and not the host, any ideas?

Notes:

  • I'm using Rails 4 and Ruby 2
  • request.domain doesn't work, this returns just the ".com" piece of the URL

Best Answer

request.original_url 

shall provide you current url in rails 4.

You can visit this resource for more info @ How do I get the current absolute URL in Ruby on Rails?

Related Question