Linking to RESTful urls within a for loop

I’m trying to use the new RESTful style of development, but am running
into a problem.

I’m trying to show a list of comments, each of which belongs to a user.
And have a link to the user’s page at the bottom of each comment.

In the routes, there is “map.resources :users”. The problem is when
using a link_to within a for loop. I don’t know what to pass to
users_url.

  1. I’ve tried users_url(comment.user.id), users_url(comment.user), and a
    few other things like that, but that gives the error of “You have a nil
    object when you didn’t expect it! The error occurred while evaluating
    nil.to_sym”.

  2. So next, i tried users_url(:id => alert.user.id). Which didn’t
    through an error. But the links don’t work with “map.resources :users”
    because they look like this: /users?id=2

What is the proper syntax in this case?

I’m using
<% for comment in @comments %>

<%= h(comment.title) %>

<%= h(comment.message) %>

Submitted by: <%= link_to( h(comment.user.name), users_url(comment.user.id) ) %>

<% end %>

On Mar 9, 2007, at 11:01 AM, Tim Michaud wrote:

In the routes, there is “map.resources :users”. The problem is when
using a link_to within a for loop. I don’t know what to pass to
users_url.

You want user_url(user) not users_url() … the former is for 1
user, the later is for all of them.