<%= request.request_uri %> / <%= request.path%>
- display current url without base url
eg: /goldberg/auth/login
<%= request.referer %>
- display previous url with base url
eg: http://www.yoursite.com/goldberg/auth/login
<%= request.env['HTTP_HOST']%>
- display base url
eg: www.yoursite.com
<%= request.env['SERVER_PROTOCOL']%>
- display protocol
eg: HTTP/1.1
<%= request.url%>
- full url
eg: http://www.yoursite.com/goldberg/auth/login
<%= request.query_parameters.size %>
- display how many parameters found in current url
url eg: www.yoursite.com/index.html?key=3&d=4
answer: 2 => (2 parameters)
<%= request.path_parameters['controller'] %>
- display controller name from current url
eg: goldberg/auth
<%= request.path_parameters['action'] %>
- display action name from current url
eg: login
<%= request.inspect%>
- It will tell you everything thats inside request.(Long request)
If you find this useful, would you like to buy me a drink? No matter more or less, it will be an encouragement for me to go further. Thanks in advance!! =)
Is there any way to get full url include hash location?
ReplyDeleteEg: www.yoursite.com/users/edit_profile#editprofile-image
I only can think of these two methods, you may have a try..
ReplyDeleteExample 1)
Create a map connection in config/routes.rb.
map.connect "/users/edit_profile/:status", :controller => "users", :action => "edit_profile"
Then, you can get the parameter in views like this, <%= params[:status] %>
Full url should be: <%= request.url+params[:status] %>
## url: www.yoursite.com/users/edit_profile/editprofile-image
Reference for Mapping: http://guides.rubyonrails.org/action_controller_overview.html
Example 2)
Make use of current_page? method
Refer site: http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-current_page-3F
Other Examples:
http://stackoverflow.com/questions/3552228/ruby-on-rails-get-url-string-parameters
http://stackoverflow.com/questions/152585/identify-get-and-post-parameters-in-ruby-on-rails
http://stackoverflow.com/questions/4151686/how-to-get-url-parameters-from-a-url-string
I tired your methods.It is not good .so please create another method.
ReplyDeleteThank you very much for this!
ReplyDeleteIt took me a while to find so it's a great relief that someone posted it! I can't believe how rude sathya above was...
dai Anonymous oru elavum puriyila da.... sathya what u said was absolutely perfect
ReplyDeletedon't know why i use [= "#{request.original_url}"] in my slim view page, it tells me that [ActionView::Template::Error (undefined method `original_url' for nil:NilClass):]
ReplyDeletePlease check the Rails version that you use, request.original_url is for Rails 3.2 or Rails 4.
DeleteFor Rails 3: Use "#{request.protocol}#{request.host_with_port}#{request.fullpath}", as request.url is now deprecated.
For Rails 2: Use request.url instead of request.request_uri.
It's very nice blog and useful for students and developer ,
ReplyDeleteRuby on Rails Online Training
It's very nice blog and useful for students and developer ,
ReplyDeleteRuby on Rails Online Training