Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - Get the current url without the GET parameters

request.url returns me this : http://localhost:3000/page?foo=bar.

Is there a method I can call to get http://localhost:3000/page , or do I have to parse the string to strip get parameters?

like image 788
MrRuru Avatar asked Feb 09 '11 16:02

MrRuru


People also ask

What is the best way to get the current request URL in Rails?

What is the best way to get the current request URL in Rails? You should use request. original_url to get the current URL.

How can you get the current absolute URL in your Ruby on Rails view?

You can write request. url instead of request. request_uri . This combines the protocol (usually http://) with the host, and request_uri to give you the full address.

How do I get the current URL in Ruby?

You should use request. original_url to get the current URL. For Rails 3: You can write "#{request.

How to access URL parameters in Rails?

Rails' params hash contains any request parameters (URL parameters or request payload) as well as routing parameters like :controller , :action , or :id . To access only URL parameters, use request. query_parameters . Routing params are available through request.


1 Answers

request.path should return what you're looking for if you're not concerned about the hostname. Otherwise you might try:

url_for(:only_path => false, :overwrite_params=>nil) 
like image 101
tadman Avatar answered Oct 15 '22 22:10

tadman