rails current path

WEDNESDAY, JUNE 23

Ruby on Rails: Request Url

<%= 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)

原文地址:https://www.cnblogs.com/lexus/p/1877911.html