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
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
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?
<% for comment in @comments %>
<%= h(comment.title) %>
<%= h(comment.message) %>
Submitted by: <%= link_to( h(comment.user.name), users_url(comment.user.id) ) %>