I'm trying to get the current url in rails using request.host
, request.url
but I have a website that are 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 show example1.com
because the example2 is getting all content from example1 and showing in the example2(parsed)
because the request.host get really the host, and request.url getting the host also I'm really need the get the url in the browser don't the host, someone can help?
OBs: I'm using rails 4 and ruby 2 OBs2: request.domain don't works, this return just ".com" of url
You should use request. original_url to get the current URL.
Ruby on Rails is an open-source web development framework, which provides Ruby developers a timesaving alternative to develop code. It is a collection of code libraries, which offer a ready-made solution for repetitive tasks like developing tables, forms or menus on the website.
Create a Rails applicationRun RubyMine and click New Project on the Welcome Screen. Name: specify a name for the project (rails-helloworld in our case). Location: specify a path to the directory in which you want to create the project. By default, RubyMine creates a directory with the same name as the project.
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?
For Rails 4 you should use request.original_url to get the current URL. More detail.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With