# Additional parameter for nested resources

**URL:** <https://www.ruby-forum.com/t/additional-parameter-for-nested-resources/144193>\
**Category:** Rails\
**Created:** [July 26, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/additional-parameter-for-nested-resources/144193 "2008-07-26T14:27:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [July 26, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/additional-parameter-for-nested-resources/144193/1 "2008-07-26T14:27:36Z")

</div>

Hi

I’m working with rails 2.1.0 and with nested resources.

My links i generate with the following helper:

link\_to @state.name, [@country, @state]

Everything works fine and the urls are correctly generated.

But now I’d like to add an additional parameter to the url like:  
/country/1/state/2?category=2

The additional parameter will only be used for filtering in the show  
action, so I don’t want to add a new nested route.

How can I generate an URL with such a parameter? I did not find any  
solution to this problem…

Thanks very much for your help!  
Julian

---

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [July 26, 2008, 2:58pm UTC](https://www.ruby-forum.com/t/additional-parameter-for-nested-resources/144193/2 "2008-07-26T14:58:05Z")

</div>

On Sat, Jul 26, 2008 at 3:21 AM, Julian [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> But now I’d like to add an additional parameter to the url like:  
> /country/1/state/2?category=2

url\_for @state.name, [@country, @state], :category =\> 2

will do the trick

–  
Gabriel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [July 27, 2008, 6:38pm UTC](https://www.ruby-forum.com/t/additional-parameter-for-nested-resources/144193/3 "2008-07-27T18:38:20Z")

</div>

On Sun, Jul 27, 2008 at 6:00 PM, Julian [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > link\_to @state.name, [@country, @state]
> 
> But url\_for expects only one parameter … Do I have the wrong rails  
> version??

Yes, It take only 1 argument, but, if you use

link\_to @state.name, country\_state\_path(@country, @state, :catergory =\>  
2)

thats seems to work (a bit tested this time 🙂 ) but it is a bit longer.

hope it will work

–  
Gabriel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [July 27, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/additional-parameter-for-nested-resources/144193/4 "2008-07-27T18:06:44Z")

</div>

On 26 Jul., 14:57, “Gabriel L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Everything works fine and the urls are correctly generated.
> 
> > But now I’d like to add anadditionalparameterto the url like:  
> > /country/1/state/2?category=2
> 
> url\_for @state.name, [@country, @state], :category =\> 2
> 
> will do the trick

But url\_for expects only one parameter … Do I have the wrong rails  
version??

Julian

---

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [July 27, 2008, 10:24pm UTC](https://www.ruby-forum.com/t/additional-parameter-for-nested-resources/144193/5 "2008-07-27T22:24:36Z")

</div>

On 27 Jul., 18:37, “Gabriel L.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > But url\_for expects only oneparameter… Do I have the wrong rails  
> > version??
> 
> Yes, It take only 1 argument, but, if you use
> 
> link\_to @state.name, country\_state\_path(@country, @state, :catergory =\> 2)
> 
> thats seems to work (a bit tested this time 🙂 ) but it is a bit longer.
> 
> hope it will work

That really works, thanks! Unfortunately I’d like to use the link\_to  
helper with the array notation [@country, @state], because the  
resource is polymorphic.

With link\_to(@state.name, [@country, @state], :catergory =\> 2),  
catgory is added as an attribute to the HTML link-tag.

Do you have an other idea? A workaround would be to write a new  
link\_to helper…

Julian

---

<div class="post-metadata">

**Author:** ![julian](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/74df32/32.png) [@julian](https://www.ruby-forum.com/u/julian)\
**Post date:** [July 27, 2008, 10:44pm UTC](https://www.ruby-forum.com/t/additional-parameter-for-nested-resources/144193/6 "2008-07-27T22:44:31Z")

</div>

On Sun, Jul 27, 2008 at 9:59 PM, Julian [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Do you have an other idea? A workaround would be to write a new  
> link\_to helper…

last idea… take a look at polymprphic\_url, and polymorphic\_path

–  
Gabriel L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
