I want to link the member id to the comment id when submitting the form

Cannot save data in intermediate table and member table

Error message
ArgumentError in CommentsController # new
Unknown key:: allow_destory. Valid keys are:: allow_destroy,: reject_if,: limit,: update_only
Applicable source code
class MemberComment</pre>
<pre><code data-language = "model">class Member</pre>
<pre><code data-language = "model">class Comment</pre>
<pre><code data-language = "controller">class CommentsController</pre>
<pre><code data-language = "Haml">. contents
    = form_for @comment do | f |
      = fields_for: members do | m |
        = m.collection_select: member_id, Member.all,: id,: name, include_blank: true
      = f.text_field: place, class: 'form__place', placeholder: 'Please enter a tourist destination'
      = f.text_area: text, class: 'form__review', placeholder: 'Please enter your comments (comments)'
      = f.text_field: image_url, class: 'form__image', placeholder: 'Paste image URL'
      = f.submit

validate: member_comment_id, presence: true for intermediate table model
I get a SyntaxError error

Supplemental information (FW/tool version etc.)
  • Answer # 1

    1) It cannot be understood that Comment and Member are many-to-many.
    You can see that Membar creates multiple comments.
    Does the comment involve multiple members?
    has_many comments
    belongs_to member

    As many-to-many
    2) Although there is a method of creating an intermediate table to create a relationship,
    There is also a method of assigning related members.
    @ comment.members = members (and so on)
    @ comment.members I think this is easier.

    3) How is the associated member determined?
    If you are a comment creator, you do not need to enter it on the new screen
    If the person creating the comment chooses from existing members,

    = fields_for (@member) do | member |
            = member.text_field: name,

    It is better to select from the member by select with