Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Find Out The Current Url / Uri In *.rhtml File

DZone's Guide to

Find Out The Current Url / Uri In *.rhtml File

·
Free Resource
// find out the current url / uri in *.rhtml file
// is quite simple with the request object


<% page = request.request_uri %>
page: <%= page %>

// but then different urls mean the same page 
// (../admin = ../admin/ = ../admin/index = ..admin/index/)
// and maybe the id is unwanted too (../admin/show/8)
// so below is an alternative with control on which parameter is used


<% page = "/" + request.path_parameters['controller'] + "/" + request.path_parameters['action'] %>
page: <%= page %>

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}