julian
July 26, 2008, 2:27pm
1
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
julian
July 26, 2008, 2:58pm
2
On Sat, Jul 26, 2008 at 3:21 AM, Julian [email protected] 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. [email protected]
julian
July 27, 2008, 6:38pm
3
On Sun, Jul 27, 2008 at 6:00 PM, Julian [email protected] 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. [email protected]
julian
July 27, 2008, 6:06pm
4
On 26 Jul., 14:57, “Gabriel L.” [email protected] 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
julian
July 27, 2008, 10:24pm
5
On 27 Jul., 18:37, “Gabriel L.” [email protected] 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
julian
July 27, 2008, 10:44pm
6
On Sun, Jul 27, 2008 at 9:59 PM, Julian [email protected] 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. [email protected]