Wednesday, September 30, 2009

Ruby on Rails : Current Url / Previous Url

Simple with the request object:

<% page1 = request.request_uri %>
<% page2 = request.referer %>
Current page: <%= page1 %>
Previous page: <%= page2 %>

If different urls mean the same page, eg: (../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 %>

No comments:

Post a Comment