[Nitro] Calculating action path

George Moschovitis george.moschovitis at gmail.com
Sun Sep 10 04:50:08 EDT 2006


I am courious, where is this needed?

-g.

PS: I am also not sure if you can already get this with the current code.


On 9/9/06, Lars Olsson <lasso at lassoweb.se> wrote:
> 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/
> _______________________________________________
> Nitro-general mailing list
> Nitro-general at rubyforge.org
> http://rubyforge.org/mailman/listinfo/nitro-general
>


-- 
http://www.gmosx.com
http://www.nitroproject.org


More information about the Nitro-general mailing list