# How can i pass instant variable in link\_to

**URL:** <https://www.ruby-forum.com/t/how-can-i-pass-instant-variable-in-link-to/145619>\
**Category:** Rails\
**Created:** [August 12, 2008, 6:58am UTC](https://www.ruby-forum.com/t/how-can-i-pass-instant-variable-in-link-to/145619 "2008-08-12T06:58:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [August 12, 2008, 6:58am UTC](https://www.ruby-forum.com/t/how-can-i-pass-instant-variable-in-link-to/145619/1 "2008-08-12T06:58:56Z")

</div>

## i have this code

# Listing jobs by Country
\<%if @postjob !=nil %\> \<%for postjob in @postjob = Postjob.find(:all, :select =\> 'DISTINCT country')%\>

\<%= link\_to "#{postjob.country}" , :controller =\> "", :action =\> "country\_list" , :id =\> p%\>

\<%end%\> \<%else%\> \<% end %\> ----------------------------------------------------------------------------------

i want to pass instant variable in link\_to , can i do this ? how? i want  
to display country wise posting ! help me !

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [August 12, 2008, 12:07pm UTC](https://www.ruby-forum.com/t/how-can-i-pass-instant-variable-in-link-to/145619/2 "2008-08-12T12:07:27Z")

</div>

Dharmdip R. wrote:

> ## i have this code
> 
> # Listing jobs by Country
> \<%if @postjob !=nil %\> \<%for postjob in @postjob = Postjob.find(:all, :select =\> 'DISTINCT country')%\>
> 
> \<%= link\_to "#{postjob.country}" , :controller =\> "", :action =\> "country\_list" , :id =\> p%\>
> 
> \<%end%\> \<%else%\> \<% end %\> ----------------------------------------------------------------------------------
> 
> i want to pass instant variable in link\_to , can i do this ? how? i want  
> to display country wise posting ! help me !

If I understand you right, you can simply write:  
\<%= link\_to postjob.country, :controller =\> “”, :action =\>  
“country\_list” , :id =\> p %\>  
Is variable p defined? Are you sure it is not “postjob.id”?

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [August 12, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/how-can-i-pass-instant-variable-in-link-to/145619/3 "2008-08-12T12:13:46Z")

</div>

Indra M. wrote:

> Dharmdip R. wrote:
> 
> > ## i have this code
> > 
> > # Listing jobs by Country
> > \<%if @postjob !=nil %\> \<%for postjob in @postjob = Postjob.find(:all, :select =\> 'DISTINCT country')%\>
> > 
> > \<%= link\_to "#{postjob.country}" , :controller =\> "", :action =\> "country\_list" , :id =\> p%\>
> > 
> > \<%end%\> \<%else%\> \<% end %\> ----------------------------------------------------------------------------------
> > 
> > i want to pass instant variable in link\_to , can i do this ? how? i want  
> > to display country wise posting ! help me !
> 
> If I understand you right, you can simply write:  
> \<%= link\_to postjob.country, :controller =\> “”, :action =\>  
> “country\_list” , :id =\> p %\>  
> Is variable p defined? Are you sure it is not “postjob.id”?

It is not working properly ! i have sent u snap , if i click on  
particular country , i can have all data belonging that country !  
please check snap shot !

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [August 12, 2008, 12:23pm UTC](https://www.ruby-forum.com/t/how-can-i-pass-instant-variable-in-link-to/145619/4 "2008-08-12T12:23:55Z")

</div>

I didn’t saw this before.

Why is controller =\> “”?

You have to add the controller name.  
If it is equal to the controller associated to the current  
view’s controller, delete this parameter completely.

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [August 12, 2008, 12:29pm UTC](https://www.ruby-forum.com/t/how-can-i-pass-instant-variable-in-link-to/145619/5 "2008-08-12T12:29:34Z")

</div>

Indra M. wrote:

> I didn’t saw this before.
> 
> Why is controller =\> “”?
> 
> You have to add the controller name.  
> If it is equal to the controller associated to the current  
> view’s controller, delete this parameter completely.

## ok ! i understand , i have done it before , i am calling same controller ! i have removed it . have u seen image ?

## \<%= link\_to “#{postjob.country}” , : action =\>“country\_list”%\>

i need help on when i click on country i want country wise listing !

n yes ! thanks for ur support !

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [August 12, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/how-can-i-pass-instant-variable-in-link-to/145619/6 "2008-08-12T14:27:50Z")

</div>

> i need help on when i click on country i want country wise listing !
> 
> n yes ! thanks for ur support !

I don’t understand your problem.

---

<div class="post-metadata">

**Author:** ![dharmdip](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/e274bd/32.png) [@dharmdip](https://www.ruby-forum.com/u/dharmdip)\
**Post date:** [August 12, 2008, 2:29pm UTC](https://www.ruby-forum.com/t/how-can-i-pass-instant-variable-in-link-to/145619/7 "2008-08-12T14:29:38Z")

</div>

Indra M. wrote:

> > i need help on when i click on country i want country wise listing !
> > 
> > n yes ! thanks for ur support !
> 
> I don’t understand your problem.

ok ! by the way thanks
