williamGeeks
williamGeeks

Reputation: 25

Missing partial comments/_comment in rails

I'm using a tutorial to get a feel for ruby, I am very much a beginner. Before posting this I have spent a couple of hours trying to resolve this myself with no luck. Sorry in advance if my explanation isn't great:

So I am getting this error screen:

error message

I am following a tutorial to make a basic reddit style app and I am trying to add the comments functionality.

Upvotes: 0

Views: 586

Answers (1)

Anthony E
Anthony E

Reputation: 11235

When you render a collection like render @comments, Rails will check the type name of the items in @comments (i.e. 'comment') then look for a partial under app/views/comments/_comment.html.erb by default (note the plural singular distinction between the partial name and the folder/collection name).

The following steps should resolve your issue:

Create a comments partial under:

app/views/comments/_comment.html.erb

Now, when you call render @comments, each item of your collection is passed to the partial as a local variable as the same name without the underscore:

In _comment.html.erb

<%# comment is defined because it matches the name of the partial %>
<%= comment.<some_attribute_on_comment> %>

Upvotes: 3

Related Questions