# Trim information from url?

**URL:** <https://www.ruby-forum.com/t/trim-information-from-url/77057>\
**Category:** Rails\
**Created:** [November 23, 2006, 8:28pm UTC](https://www.ruby-forum.com/t/trim-information-from-url/77057 "2006-11-23T20:28:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [November 23, 2006, 8:28pm UTC](https://www.ruby-forum.com/t/trim-information-from-url/77057/1 "2006-11-23T20:28:28Z")

</div>

hi,  
my url after performing a call to a database looks like this:

[http://localhost:3000/myapp/view?scat=3&mcat=4](http://localhost:3000/myapp/view?scat=3&mcat=4)

is there a way to chop off the “?scat=3&mcat=4” part of the url?

---

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [November 23, 2006, 8:31pm UTC](https://www.ruby-forum.com/t/trim-information-from-url/77057/2 "2006-11-23T20:31:44Z")

</div>

well without a refresh or a render i think not

koloa wrote:

> hi,  
> my url after performing a call to a database looks like this:
> 
> [http://localhost:3000/myapp/view?scat=3&mcat=4](http://localhost:3000/myapp/view?scat=3&mcat=4)
> 
> is there a way to chop off the “?scat=3&mcat=4” part of the url?

---

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [November 23, 2006, 8:36pm UTC](https://www.ruby-forum.com/t/trim-information-from-url/77057/3 "2006-11-23T20:36:55Z")

</div>

koloa wrote:

> hi,  
> my url after performing a call to a database looks like this:
> 
> [http://localhost:3000/myapp/view?scat=3&mcat=4](http://localhost:3000/myapp/view?scat=3&mcat=4)
> 
> is there a way to chop off the “?scat=3&mcat=4” part of the url?

How about

url.sub(/?.\*/, ‘’)

Example:

irb(main):015:0\> url = ‘[http://localhost:3000/myapp/view?scat=3&mcat=4](http://localhost:3000/myapp/view?scat=3&mcat=4)’  
=\> “[http://localhost:3000/myapp/view?scat=3&mcat=4](http://localhost:3000/myapp/view?scat=3&mcat=4)”  
irb(main):016:0\> url.sub(/?.\*/, ‘’)  
=\> “[http://localhost:3000/myapp/view](http://localhost:3000/myapp/view)”

Proper ? should normally arrive escaped in the URL.

Stephan

---

<div class="post-metadata">

**Author:** ![koloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/4bbf92/32.png) [@koloa](https://www.ruby-forum.com/u/koloa)\
**Post date:** [November 23, 2006, 9:23pm UTC](https://www.ruby-forum.com/t/trim-information-from-url/77057/4 "2006-11-23T21:23:55Z")

</div>

koloa wrote:

> my url after performing a call to a database looks like this:
> 
> [http://localhost:3000/myapp/view?scat=3&mcat=4](http://localhost:3000/myapp/view?scat=3&mcat=4)
> 
> is there a way to chop off the “?scat=3&mcat=4” part of the url?

Can you fetch that page via POST instead of GET? The latter sends the  
display data as a batch of variables inside the POSTing message, not as  
part  
of the URL.

Your calling function might have a :method option to switch to ‘post’.

–  
Phlip  
[Redirecting...](http://www.greencheese.us/ZeekLand) ← NOT a blog!!!
