# Where to put custom URL parser

**URL:** <https://www.ruby-forum.com/t/where-to-put-custom-url-parser/190916>\
**Category:** Rails\
**Created:** [June 30, 2010, 5:53pm UTC](https://www.ruby-forum.com/t/where-to-put-custom-url-parser/190916 "2010-06-30T17:53:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![PsiPro](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ba8739/32.png) [@PsiPro](https://www.ruby-forum.com/u/PsiPro)\
**Post date:** [June 30, 2010, 5:53pm UTC](https://www.ruby-forum.com/t/where-to-put-custom-url-parser/190916/1 "2010-06-30T17:53:04Z")

</div>

I’ve written a routine for encoding and decoding custom urls.

My route looks like:

map.browse ‘items/browse/\*query’, :controller =\> ‘items’, :action =\>  
‘browse’

Now the param query is suposed to look something like:

manufactured\_by\_Sombody/is\_tagged\_this\_and\_that/is\_tagged\_foo\_or\_bar/  
is\_not\_tagged\_baz\_and\_nitch

Now I’ve got the routines built to decode this and turn it into a  
thinking sphinx search hash, and I have the code to turn the TS hash  
into that url. My problem is, I need access to that code in both the  
controller and the view, where is the best place to put this code so  
it is accessible in those two locations without repeating the code.

Is there a better way to do this, becaue at the moment in order to  
form links I am using code like

link\_to “foo”, browse\_url(:query =\> parse\_browse\_url(hash))

I’d appreciate any input.

-Brian
