# Url reformatting

**URL:** <https://www.ruby-forum.com/t/url-reformatting/132065>\
**Category:** Rails\
**Created:** [March 16, 2008, 9:14am UTC](https://www.ruby-forum.com/t/url-reformatting/132065 "2008-03-16T09:14:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![srikanth\_u37](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@srikanth\_u37](https://www.ruby-forum.com/u/srikanth_u37)\
**Post date:** [March 16, 2008, 9:14am UTC](https://www.ruby-forum.com/t/url-reformatting/132065/1 "2008-03-16T09:14:27Z")

</div>

Hi,

I am new to ruby on rails and i have urls which are in the form of

[http://demo.com/demo/home?demo=10](http://demo.com/demo/home?demo=10)  
i want to reformat the above url to user friendly way like  
[http://demo.com/demo/home/10](http://demo.com/demo/home/10)

Is there any way how to do it.

Thanks  
Srikanth

---

<div class="post-metadata">

**Author:** ![srikanth\_u37](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@srikanth\_u37](https://www.ruby-forum.com/u/srikanth_u37)\
**Post date:** [March 16, 2008, 10:40am UTC](https://www.ruby-forum.com/t/url-reformatting/132065/2 "2008-03-16T10:40:24Z")

</div>

On 16 Mar 2008, at 09:14, Srikanth Gop wrote:

> I am new to ruby on rails and i have urls which are in the form of
> 
> [http://demo.com/demo/home?demo=10](http://demo.com/demo/home?demo=10)  
> i want to reformat the above url to user friendly way like  
> [http://demo.com/demo/home/10](http://demo.com/demo/home/10)

Looks like named routes to me (code in routes.rb):

map.demo “/demo/home/:demo”, :controller =\> “demo”, :action =\> “home”

You can then just use “demo\_path(:demo =\> 10)” in your controllers/  
views to get the url you want.

Though I think you’d be better off rethinking your whole app structure  
into something more RESTful. Getting a book on Rails (e.g. The Rails  
Way) could be a good idea.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![srikanth\_u37](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/90db22/32.png) [@srikanth\_u37](https://www.ruby-forum.com/u/srikanth_u37)\
**Post date:** [March 17, 2008, 6:30am UTC](https://www.ruby-forum.com/t/url-reformatting/132065/3 "2008-03-17T06:30:20Z")

</div>

Peter De Berdt wrote:

> On 16 Mar 2008, at 09:14, Srikanth Gop wrote:
> 
> > I am new to ruby on rails and i have urls which are in the form of
> > 
> > [http://demo.com/demo/home?demo=10](http://demo.com/demo/home?demo=10)  
> > i want to reformat the above url to user friendly way like  
> > [http://demo.com/demo/home/10](http://demo.com/demo/home/10)
> 
> Looks like named routes to me (code in routes.rb):
> 
> map.demo “/demo/home/:demo”, :controller =\> “demo”, :action =\> “home”
> 
> You can then just use “demo\_path(:demo =\> 10)” in your controllers/  
> views to get the url you want.
> 
> Though I think you’d be better off rethinking your whole app structure  
> into something more RESTful. Getting a book on Rails (e.g. The Rails  
> Way) could be a good idea.
> 
> Best regards
> 
> Peter De Berdt

Thanks Peter for your suggestion and help… I will look into it

Regards,  
srikanth
