0

in my routes.rb i have

match "monsters/:category" => "monsters#index"

i have a bunch of links such as

  • Water
  • Fire
  • Earth
  • Flying

however im having trouble passing "Water" or "Fire" as the :category for my routes. how exactly do i do that?

i tried something like...

<%= link_to "Water", "monsters/water"(:category => "water") %>

but syntactically i cant do that. how do i pass in "water" as the :category symbol?

thanks!

Sasha
  • 3,281
  • 7
  • 34
  • 52

1 Answers1

3

You don't need to specify :category in the link_to. While doing this:

<%= link_to "Water", "monsters/water" %>

Your routes will match water to the :category parameter, and therefore in your controller you can access params[:category] and water will be the value. Notice that in the routes you are already saying that whatever comes after the "monsters/" will be recognized as the category parameter.

Notice that if you have Named Routes, you can pass parameters like this:

<%= link_to "Up", monster_path(:category => "water") %>
Nobita
  • 23,519
  • 11
  • 58
  • 87