The member table and the comment table have a many-to-many relationship
I want to bring member's name through an intermediate table

Error message
NoMethodError in Comments # index
undefined method `member 'for nil: NilClass
Applicable source code
[email protected] comments.each do | comment |
        = comment.place
        [email protected] comment.member.each do | member |
          = member.name
Rails.application.routes.draw do
  # devise_for: users
  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
  root to: 'posts # index'
  resources: posts, only: [: index]
  resources: comments, only: [: index,: show]
class CreateMemberComments
class CreateComments
class CreateMembers
class CreateMembers
class CommentsController
class Member
class Comment
class MemberComment
I tried extracting it with the find method with reference to this article, but it was no use.

Supplemental information (FW/tool version etc.)

Please provide more information here.
Since it is the first post, you may not have the necessary information.

  • Answer # 1

    I would like to see the related definitions of class member and class comment ...
    At least here is wrong.
    [email protected] comment.member.each do | member |is
    -comment.members.each do | member |