# Quick question about \<% link\_to something, :action =\>

**URL:** <https://www.ruby-forum.com/t/quick-question-about-link-to-something-action/56636>\
**Category:** Rails\
**Created:** [April 2, 2006, 12:58am UTC](https://www.ruby-forum.com/t/quick-question-about-link-to-something-action/56636 "2006-04-02T00:58:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bbqInKoloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cdc98d/32.png) [@bbqInKoloa](https://www.ruby-forum.com/u/bbqInKoloa)\
**Post date:** [April 2, 2006, 12:58am UTC](https://www.ruby-forum.com/t/quick-question-about-link-to-something-action/56636/1 "2006-04-02T00:58:12Z")

</div>

Hi,  
I have a basic question. when i use

\<% link\_to show\_city,  
:action =\> ‘my defined action’  
:id =\> ‘something’ %\>

//what is ID here? is this the parameter in my mysql db?

basically

how can i put a parameter into the link that when it hits my function,  
it can tell my function what to use as a condition to search. for  
example i have a table of cities that i want to all list as links. when  
the user clicks the link of a city, i want to generate a new page with  
all information related to the city link the person pressed.

---

<div class="post-metadata">

**Author:** ![bbqInKoloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cdc98d/32.png) [@bbqInKoloa](https://www.ruby-forum.com/u/bbqInKoloa)\
**Post date:** [April 2, 2006, 6:46am UTC](https://www.ruby-forum.com/t/quick-question-about-link-to-something-action/56636/2 "2006-04-02T06:46:51Z")

</div>

Oh, I should mention that if it does in fact say:

id =\> ‘something’

the string ‘something’ is what will be accessed by

params[:id]

In my cases, id will be an item from your database.

-Adam

---

<div class="post-metadata">

**Author:** ![bbqInKoloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cdc98d/32.png) [@bbqInKoloa](https://www.ruby-forum.com/u/bbqInKoloa)\
**Post date:** [April 2, 2006, 4:47pm UTC](https://www.ruby-forum.com/t/quick-question-about-link-to-something-action/56636/3 "2006-04-02T16:47:31Z")

</div>

hey adam, thanks so much for the response! appreciate the help.

Adam B. wrote:

> Oh, I should mention that if it does in fact say:
> 
> id =\> ‘something’
> 
> the string ‘something’ is what will be accessed by
> 
> params[:id]
> 
> In my cases, id will be an item from your database.
> 
> -Adam

---

<div class="post-metadata">

**Author:** ![bbqInKoloa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cdc98d/32.png) [@bbqInKoloa](https://www.ruby-forum.com/u/bbqInKoloa)\
**Post date:** [April 2, 2006, 6:44am UTC](https://www.ruby-forum.com/t/quick-question-about-link-to-something-action/56636/4 "2006-04-02T06:44:59Z")

</div>

bbqInKoloa wrote:

> Hi,  
> I have a basic question. when i use
> 
> \<% link\_to show\_city,  
> :action =\> ‘my defined action’  
> :id =\> ‘something’ %\>
> 
> //what is ID here? is this the parameter in my mysql db?

It’s a parameter that will be sent to the linked page, and can be  
accesed with: params[:id] in ‘my defined action.’

You can make up your own, for example:

\<% link\_to ‘Show’, :action =\> ‘show’, :id =\> ‘something’, :type =\>  
‘city’ %\>

and you could access the string ‘city’ with params[:type].

> basically
> 
> how can i put a parameter into the link that when it hits my function,  
> it can tell my function what to use as a condition to search. for  
> example i have a table of cities that i want to all list as links. when  
> the user clicks the link of a city, i want to generate a new page with  
> all information related to the city link the person pressed.

Assuming your table looks something like this:

\<% for city in Cities.find\_all %\> \<% end %\>

This will create a table of links, which will be named according to  
their city, and will link to the action “show\_city” in your controller.  
In your controller code you’ll put a line something like this:

def show\_city  
@city = Cities.find(params[:id])  
…  
end

and in your file “show\_city.rhtml”, you’ll put stuff like:

Hope that helps.

-Adam

| \<% link\_to city.name, :action =\> 'show\_city', :id =\> city %\> | @city.name | @city.state |
