So what I want to do is determine if the current link is \'active\', i.e. if this link was just clicked by the user.
If it is, then I want to apply the class=s
Bonkydog already gave you this hint in his comment, here it is as a working Sinatra example (using HAML instead of ERB though):
require 'sinatra'
require 'haml'
get '/bar' do
@urls = ['/foo', '/bar', '/baz']
haml :index
end
__END__
@@ index
%ul
-@urls.each do |url|
%li{:class => request.path_info == url ? 'selected' : nil}
%a{:href => url}
=url
Edit: After a clarification in the comment, turns out that this seems to be pure HTML/CSS problem. Check out :target
pseudo selector:
Not sure whether some browsers support it though.