Quick question about <% link_to something, :action =>


#1

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.


#2

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


#3

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


#4

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