Apane101
Apane101

Reputation: 1123

Comments not displaying in songs#show.html.erb

The comments don't appear to be showing after they are submitted (created). If you look at songs#show.html.erb you'll see the comments code. Not sure why they aren't showing, I've looked into how Ryan Bates does his comments and my code is identical. Please advise :)

Note: for what it's worth I'm running rails 4.

Upvotes: 0

Views: 89

Answers (1)

sites
sites

Reputation: 21785

Your problem is in song/show variable @song is ok, but then you render comments/_form which uses @comment which is set to a new comment without song_id set.

Yo build a comment with song_id set to id of @song you could:

# songs_controller.rb
def show
  @comment = @song.comments.build
end

Upvotes: 1

Related Questions