Home>
missing required keys: I'm having trouble resolving the [: id] error.

When the poster of the prototype and the logged-in user are the same, if you post a comment in the blank, the following error message will be displayed.
If the poster and the logged-in user are different, no error will occur even if the same operation is performed.

ActionController :: UrlGenerationError in Comments # create
Showing /Users/ohamamakoto/projects/protospace-30503/app/views/prototypes/show.html.erb where line # 11 raised:
No route matches {: action =>"edit",: controller =>"prototypes",: prototype_id =>"3"},

 missing required keys: [: id]
9<% if current_user == @ prototype.user%>10 11<% = link_to "edit", edit_prototype_path, class:: prototype__btn%>12<% = link_to "Delete", prototype_path, class:: prototype__btn, method :: DELETE%>            <% end%>
Corresponding source code
<main>        <p>    <% = @ prototype.title%>  </p>  <% = link_to "by # {@ prototype.user.name}", user_path (@ prototype.user), class ::: prototype__user%>  <% # Display the following if the poster of the prototype and the logged-in user are the same%>  <% if current_user == @ prototype.user%>              <% = link_to "edit", edit_prototype_path, class:: prototype__btn%>      <% = link_to "Delete", prototype_path, class:: prototype__btn, method:: DELETE%>            <% end%>  <% # // Show the above if the prototype poster and the logged-in user are the same%>          <% = image_tag @ prototype.image%>                          <p>Catch copy</p>      <p>        <% = @ prototype.catch_copy%>      </p>                      <p>Concept</p>      <p>        <% = @ prototype.concept%>      </p>                        <% # Display the following comment posting form for logged-in users%>     <% if current_user%>       <% = form_with model: [@prototype, @comment],local: true do | f |%>                       <% = f.label: comment, "comment"%><br />           <% = f.text_field: comment%>                                   <% = f.submit "submit", class :: form__btn%>                    <% end%>      <% end%>    <% # // Display the above for logged-in users%>    <ul>      <% # Describe the process of listing the comments associated with the post%>        <li>          <% if @comments%>            <% @ comment.each do | comment |%>            <p>              <% = link_to comment.user.name, user_path (comment.user), class :: comment_user%>              <% = comment.comment%>            </p>            <% end%>          <% end%>        </li>      <% # // Describe the process to list the comments associated with the post%>    </ul>        </main>
           Prototype editing     <% # Display form with partial template%>  <% = render'form', local: {prototype: @prototype}%>  
class PrototypesController
class CommentsController
What I tried

I reviewed whether the prefix was wrong, but there was no problem.
Please tell me why the error occurs only when the poster and the logged-in user are the same.
If i have any missing information, thank you.

  • Answer # 1

    Here on line 11<% = link_to "edit", edit_prototype_path, class:: prototype__btn%>so
    missing required keys: [: id]Because it is said, to guess from the name@prototypeParameter

    <% = link_to "edit", edit_prototype_path (@prototype), class:: prototype__btn%>