20

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
Wagner Moreira
  • 1,033
  • 1
  • 16
  • 40
  • did you tried `request.original_url`? – rony36 Jan 29 '14 at 11:59
  • 1
    @Lain Your effort to capitalize "i" in a whole lot of questions is appreciated, but try to make edits _substantial_. More often than not other things need fixing, too. – Mathias Müller Mar 07 '14 at 09:02
  • possible duplicate of [How do I get the current absolute URL in Ruby on Rails?](http://stackoverflow.com/questions/2165665/how-do-i-get-the-current-absolute-url-in-ruby-on-rails) – Brad Werth Sep 17 '14 at 05:01
  • http://blog.grepruby.com/2015/04/absolute-url-full-url-in-rails-4.html – user3118220 Apr 20 '15 at 10:33

2 Answers2

32
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?

Community
  • 1
  • 1
Alok Anand
  • 3,346
  • 1
  • 20
  • 17
2

For Rails 4 you should use request.original_url to get the current URL. More detail.

Egalitarian
  • 2,168
  • 7
  • 24
  • 33