Topic: Links not working

Hello,

I have yet another question, I think I must have the record of how many things to need help with in a few days time.  anyway, I have this here,

<% for category in @categories %>
  <% for column in Category.content_columns %>
    <%= link_to category.send(column.name), :action => "index", :category => "#{category.name}" %><br />
  <% end %>
<% end %>

What is supposed to happen is it loops through the categories and lists the names.  Each name is a link to a page with all the items in that category.  I get no error message but all that happens is the address bar in the browser changes to the category like this,

http://localhost:3000/main_page?category=Lakes+and+Ponds

but it doesn't actually go there. 

any suggestions?

Thanks,

Dan

Re: Links not working

First of all, you are looping through the columns of each category in that code. You probably don't want to loop through each column, so take out the "for column in Category.content_columns" loop.

<% for category in @categories %>
  <%= link_to category.send(column.name), :action => "index", :category => "#{category.name}" %><br />
<% end %>

So now we have a loop of categories. To get the name of a category, all you have to do is call "category.name". Right now you are doing stuff with the "column" variable (which is no longer there anyway since we took out that loop).

<% for category in @categories %>
  <%= link_to category.name, :action => "index", :category => "#{category.name}" %><br />
<% end %>

The next problem is you are linking to the "index" action. I'm assuming this code is in the index action already. You probably want the "show" action.

<% for category in @categories %>
  <%= link_to category.name, :action => "show", :category => "#{category.name}" %><br />
<% end %>

One last change, you are setting the "category" parameter to the name of the category. Normally in Rails you want to set the "id" attribute to the category. Like so:

<% for category in @categories %>
  <%= link_to category.name, :action => "show", :id => category %><br />
<% end %>

There we go, this should link to the "show" action in your controller so you can display the category there. Hope that helps.

Railscasts - Free Ruby on Rails Screencasts