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 =>
and you could access the string ‘city’ with params[:type].
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 %>
|<% link_to city.name, :action => 'show_city', :id => city %>
<% 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:
@city = Cities.find(params[:id])
and in your file “show_city.rhtml”, you’ll put stuff like:
Hope that helps.