[Nitro] Calculating action path
Lars Olsson
lasso at lassoweb.se
Sat Sep 9 04:48:50 EDT 2006
Hi list,
I don't know whether there already exists functionality for calculating
the action path (if so, please tell me where!), bur since I need this
functionality in certain scenarios i added the following code to the
request object. Perhaps someone else might find it useful too.
module Nitro
module Request
def action_path
if uri
offset = uri.include?('?') ? 2 : 1
uri[0..uri.length - query_string.length - offset].chomp('/')
else
''
end
end
end
end
EXAMPLE
=======
Lets say we have an action that respond to http://server/somedir/myaction
request.action_path will return "/somedir/myaction" in all the following
scenarios:
http://server/somedir/myaction
http://server/somedir/myaction/
http://server/somedir/myaction?one=1&two=2&three=3
http://server/somedir/myaction/foo
http://server/somedir/myaction/foo?one=1&two=2&three=3
http://server/somedir/myaction/foo/bar
http://server/somedir/myaction/foo/bar?one=1&two=2&three=3
and so on...
Improvements are most welcome.
Sincerely
/lasso
--
________________________________________
Lars Olsson
lasso at lassoweb.se
http://www.lassoweb.se/
More information about the Nitro-general
mailing list