Home>

While creating a chat room app, when I tried to respond to a comment, I got a routing error.

What I want to do is Post (save response), but I don't understand why it's a patch.
I don't think the routing settings themselves are wrong ...

[Gyazo on error message screen]
https://gyazo.com/7a736db0077689339ee47b8b60c31d63

Error message
Routing Error
No route matches [PATCH] "/ comments/50/responses"
Corresponding source code
[Response new.html.erb]          <% = form_with model: [@response, @comment],

url: comment_responses_path (@comment), local: true do | f |%>    <% = f.text_area: response_text, placeholder: "Ask a question", class: "comment-text"%>    <% = hidden_field_tag: comment_id, @ comment.id%>  <p>    <p>If i can answer the questions of other students, please answer positively!</p>  </p>  <br>  <% = f.submit "Ask a question", class: "comment-btn"%>   <% = link_to'back', root_path%>  <% end%>     <Question list>   <% if @responses%>    <% @ responses.each do | response |%>             <% if current_user.genre == "teacher"%>      <p>        <strong><% = link_to comment.user.name, "#", class: "comment-nickname"%></strong>      </p>      <% elsif current_user.genre == "student"%>      <strong class = "comment-nickname">anonymous</strong>      <% end%>      <p>        <% = link_to comment.text, new_comment_response_path (comment)%>      </p><ul>        <p><% = response.created_at.to_s (: datetime_jp)%></p>        <p><% = response.created_at.to_s (: datetime_jp2)%></p>      </ul>       <% if current_user.genre == "teacher"%>      <p>        <% = link_to message_comment_path (@ comment.id, response.id), method:: delete, class: "delete-button" do%>        <i></i>        <% end%>      </p>      <% elsif user_signed_in?&&current_user.id == response.user_id%>      <p>        <% = link_to message_comment_path (@ comment.id, response.id), method:: delete, class: "delete-button" do%>        <i></i>        <% end%>      </p>      <% end%>      <p>              <% end%>  <% end%>  
class ResponsesController</pre>
<pre><code data-language = "Ruby">[Routes.rb]
Rails.application.routes.draw do
  devise_for: users
  get'messages/index'
  get'comments/index'
  root to: "rooms # index"
  resources: users
  resources: rooms do
    resources: messages
  end
  resources: messages do
    resources: comments
end
  resources: comments do
    resources: agrees, only: [: create,: destroy]
end
  resources: comments do
    resources: responses, only: [: new,: create,: destroy]
end
end
comment_responses POST/comments /: comment_id/responses (.: format) responses # create
new_comment_response GET/comments /: comment_id/responses/new (.: format) responses # new
comment_response DELETE/comments /: comment_id/responses /: id (.: format) responses # destroy
What I tried

Please describe here what you have tried for the problem.

Supplementary information (FW/tool version, etc.)

Please provide more detailed information here.

  • Answer # 1

    form_with model: [@response, @comment]
    @comment = Comment.find (params [: comment_id]) I wonder if the URL etc. has been decided for the comment.

    If it is a response to a comment
    form_with model: [@comment, @response]