# Problem in passing 2 params

**URL:** <https://www.ruby-forum.com/t/problem-in-passing-2-params/131471>\
**Category:** Rails\
**Created:** [March 10, 2008, 1:39pm UTC](https://www.ruby-forum.com/t/problem-in-passing-2-params/131471 "2008-03-10T13:39:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vidya1111](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b3f665/32.png) [@vidya1111](https://www.ruby-forum.com/u/vidya1111)\
**Post date:** [March 10, 2008, 1:39pm UTC](https://www.ruby-forum.com/t/problem-in-passing-2-params/131471/1 "2008-03-10T13:39:51Z")

</div>

I am trying to pass 2 parameters to the ‘new’ action in the  
plans\_controller, something like this.

```
  "new_plan_path+"?id1=1&id2=3"

```

Only ‘id1’ is passed and the “&” symbol is rewritten as ‘&’, hence  
‘id2’ is not received using params[:id2] in new method.

Somebody suggest an alternate please…

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![vidya1111](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b3f665/32.png) [@vidya1111](https://www.ruby-forum.com/u/vidya1111)\
**Post date:** [March 10, 2008, 3:12pm UTC](https://www.ruby-forum.com/t/problem-in-passing-2-params/131471/2 "2008-03-10T15:12:20Z")

</div>

Vidya Ramachandren wrote:

> ```
> "new_plan_path+"?id1=1&id2=3"
> 
> ```
> 
> Only ‘id1’ is passed and the “&” symbol is rewritten as ‘&’, hence  
> ‘id2’ is not received using params[:id2] in new method.

Use something like:

\<%= link\_to ‘New plan’, url\_for(:action =\> :new, :id1 =\> 2, :id2 =\> 3)  
%\>

This will create the tag:

[New plan](https://www.ruby-forum.com/plans/new?id1=2&id2=3)

And the #new action will see both params[:id1] and params[:id2]

---

<div class="post-metadata">

**Author:** ![vidya1111](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b3f665/32.png) [@vidya1111](https://www.ruby-forum.com/u/vidya1111)\
**Post date:** [March 10, 2008, 3:42pm UTC](https://www.ruby-forum.com/t/problem-in-passing-2-params/131471/3 "2008-03-10T15:42:22Z")

</div>

Mark B. wrote:

> Use something like:
> 
> \<%= link\_to ‘New plan’, url\_for(:action =\> :new, :id1 =\> 2, :id2 =\> 3)  
> %\>

Actually, this is better as:

\<%= link\_to ‘New plan’, new\_plan\_path(:id1 =\> 2, :id2 =\> 3) %\>

---

<div class="post-metadata">

**Author:** ![vidya1111](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b3f665/32.png) [@vidya1111](https://www.ruby-forum.com/u/vidya1111)\
**Post date:** [March 10, 2008, 4:06pm UTC](https://www.ruby-forum.com/t/problem-in-passing-2-params/131471/4 "2008-03-10T16:06:28Z")

</div>

Still I am getting nil value for the id2 ☹

Mark B. wrote:

> Mark B. wrote:
> 
> > Use something like:
> > 
> > \<%= link\_to ‘New plan’, url\_for(:action =\> :new, :id1 =\> 2, :id2 =\> 3)  
> > %\>
> 
> Actually, this is better as:
> 
> \<%= link\_to ‘New plan’, new\_plan\_path(:id1 =\> 2, :id2 =\> 3) %\>

---

<div class="post-metadata">

**Author:** ![vidya1111](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b3f665/32.png) [@vidya1111](https://www.ruby-forum.com/u/vidya1111)\
**Post date:** [March 10, 2008, 4:29pm UTC](https://www.ruby-forum.com/t/problem-in-passing-2-params/131471/5 "2008-03-10T16:29:57Z")

</div>

Vidya Ramachandren wrote:

> Still I am getting nil value for the id2 ☹

I’ve checked this against Safari, Firefox and IE and all pass the params  
correctly. (This is with Rails 2, but that shouldn’t matter.)

Can you look at the web page source with the link on it and post the  
link text and also the parameters from your log file from selecting the  
link?

---

<div class="post-metadata">

**Author:** ![vidya1111](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/b3f665/32.png) [@vidya1111](https://www.ruby-forum.com/u/vidya1111)\
**Post date:** [March 10, 2008, 7:23pm UTC](https://www.ruby-forum.com/t/problem-in-passing-2-params/131471/6 "2008-03-10T19:23:27Z")

</div>

Hi

Try this

link\_to(“abcabcabd”, :controller=\>‘controller’, :action=\>‘action’, :id=\>  
123, :show=\>“true”)

it will create a link something like :

abcabc

on next page\<%= params[:id]%\> will be equal to 123 and \<%=  
params[:show]%\> equal to true

i hope it will help

Ajit

On Mar 10, 8:39 am, Vidya Ramachandren \<rails-mailing-l…@andreas-
