Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails how to get current URL?

Tags:

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

like image 813
Wagner Moreira Avatar asked Jan 29 '14 11:01

Wagner Moreira


People also ask

How do I get the current URL in Ruby?

You should use request. original_url to get the current URL.

Is Ruby on Rails a framework?

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.

How can you create a new Rails project?

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.


2 Answers

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?

like image 121
Alok Anand Avatar answered Sep 28 '22 12:09

Alok Anand


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

like image 41
Egalitarian Avatar answered Sep 28 '22 11:09

Egalitarian