# How to generate this URL

**URL:** <https://www.ruby-forum.com/t/how-to-generate-this-url/184257>\
**Category:** Rails\
**Created:** [February 27, 2010, 11:55am UTC](https://www.ruby-forum.com/t/how-to-generate-this-url/184257 "2010-02-27T11:55:15Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![east](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e95f7d/32.png) [@east](https://www.ruby-forum.com/u/east)\
**Post date:** [February 27, 2010, 11:55am UTC](https://www.ruby-forum.com/t/how-to-generate-this-url/184257/1 "2010-02-27T11:55:15Z")

</div>

I’m stumped trying to generate an URL for a working route. I’ve this  
route definition:

map.connect ‘foo/:foo\_id/propose\_something/:zap\_id’,  
:controller =\> “foo”,  
:action =\> “propose\_something”

When I browse to this url:  
[http://localhost:3000/foo/2/propose\_something/5](http://localhost:3000/foo/2/propose_something/5),  
my propose\_something method gets invoked with the correct params  
hash. So one would think that all is good, but I’m stuck trying to  
generate the corresponding URL to pass to link\_to.

I would think that this would do it:  
url\_for(:controller =\> “foo”, :action =\> ‘propose\_something’, :foo\_id  
=\> 1, :zap\_id =\> 13)

But this generates this URL:  
[http://localhost:3000/foo/propose\_something?foo\_id=1&zap\_id=13](http://localhost:3000/foo/propose_something?foo_id=1&zap_id=13)

To work around this, I’ve constructed the string manually, but that  
feels nasty in all sorts of ways…

Can someone point out what the heck I’m doing wrong?

Thanks,  
east

---

<div class="post-metadata">

**Author:** ![east](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/e95f7d/32.png) [@east](https://www.ruby-forum.com/u/east)\
**Post date:** [February 27, 2010, 1:45pm UTC](https://www.ruby-forum.com/t/how-to-generate-this-url/184257/2 "2010-02-27T13:45:52Z")

</div>

On Fri, 2010-02-26 at 17:44 -0800, east wrote:

> generate the corresponding URL to pass to link\_to.
> 
> Can someone point out what the heck I’m doing wrong?

* * *

url\_for(:controller =\> “foo”, :action =\> (’/’ + :foo\_id +  
‘/propose\_something’), :zap\_id =\> 13)

You might not need the parens but it tends to help me spot what the  
intent was right away.

That said, I probably would rethink my ‘routes’ and use routes and  
methods that tended towards standardization and have my methods parse  
the params.

Craig

–  
This message has been scanned for viruses and  
dangerous content by MailScanner, and is  
believed to be clean.
