# How to create an action with two params

**URL:** <https://www.ruby-forum.com/t/how-to-create-an-action-with-two-params/88506>\
**Category:** Rails\
**Created:** [March 12, 2007, 6:04am UTC](https://www.ruby-forum.com/t/how-to-create-an-action-with-two-params/88506 "2007-03-12T06:04:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [March 12, 2007, 6:04am UTC](https://www.ruby-forum.com/t/how-to-create-an-action-with-two-params/88506/1 "2007-03-12T06:04:49Z")

</div>

I’m implementing an action that needs two parameters in the url like

do/a/b

and in the controller  
I would like to access a and b

like params[:id]

Please let me know if there’s any solution.

THanks

Abon

---

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [March 12, 2007, 6:09am UTC](https://www.ruby-forum.com/t/how-to-create-an-action-with-two-params/88506/2 "2007-03-12T06:09:38Z")

</div>

Bontina C. wrote:

> I’m implementing an action that needs two parameters in the url like
> 
> do/a/b
> 
> and in the controller  
> I would like to access a and b
> 
> like params[:id]
> 
> Please let me know if there’s any solution.

In routes.rb create something like:

map.connect ‘do/:a/:b’, :controller =\> “do”, :action =\> “index”

In controller “do” :a and :b will be accessible as params[:a] and  
params[:b].

–  
Michael W.

---

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [March 12, 2007, 7:43am UTC](https://www.ruby-forum.com/t/how-to-create-an-action-with-two-params/88506/3 "2007-03-12T07:43:56Z")

</div>

THanks for the solution.  
Btw, it seems not ok to have tow ids in link\_to.

Abon  
Michael W. wrote:

> Bontina C. wrote:
> 
> > I’m implementing an action that needs two parameters in the url like
> > 
> > do/a/b
> > 
> > and in the controller  
> > I would like to access a and b
> > 
> > like params[:id]
> > 
> > Please let me know if there’s any solution.
> 
> In routes.rb create something like:
> 
> map.connect ‘do/:a/:b’, :controller =\> “do”, :action =\> “index”
> 
> In controller “do” :a and :b will be accessible as params[:a] and  
> params[:b].
> 
> –  
> Michael W.

---

<div class="post-metadata">

**Author:** ![abon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/45deac/32.png) [@abon](https://www.ruby-forum.com/u/abon)\
**Post date:** [March 12, 2007, 7:54am UTC](https://www.ruby-forum.com/t/how-to-create-an-action-with-two-params/88506/4 "2007-03-12T07:54:45Z")

</div>

Bontina C. wrote:

> THanks for the solution.  
> Btw, it seems not ok to have tow ids in link\_to.

In the link\_to helper method, any parameters that you specify will be  
matched  
to the route that Rails is going to use, and any “extra” parameters  
(parameters not named in the route) will be tacked on as URL query  
parameters.

So you can do:

link\_to “link name”, :controller =\> “do”, :action =\> “index”, :a =\>  
“a\_blah”,  
"b =\> “b\_blah”, :c =\> “c\_blah”

and you get (using the route in my previous post):

[link\_name](https://www.ruby-forum.com/do/a_blah/b_blah?c=c_blah)

–  
Michael W.
