Home>

I tried to add a function to report posted reviews.missing required keys:I get the error

ActionController :: UrlGenerationError in Reviews # index
 No route matches {: action =>"create",: controller =>"reports",
: recipe_id =>#<Review id: 1, user_id: 1, recipe_id: 1, content: "aaa", score: 5, created_at: "2020-09-15 14:30:51", updated_at: "2020-09 -15 14:30:51 ">},
 missing required keys: [: review_id]


The report function allows you to write a review in the posted recipe, and I am trying to add it to that review

recipe_review_reports DELETE/recipes /: recipe_id/reviews /: review_id/reports (.: format) reports # destroy
                      POST/recipes /: recipe_id/reviews /: review_id/reports (.: format) reports # create


abovereview_idI'm wondering if I can't get it and I'm getting an error, but I don't know how to solve it (I don't know if there's a cause I'm thinking about in the first place)

routes.rb ↓

Rails.application.routes.draw do
  resources: recipes do
    resource: favorites, only: [: create,: destroy]
    resources: reviews, only: [: index,: create] do
      resource: reports, only: [: create,: destroy]
    end
  end


reviews \ index.html.erb ↓

<% @ reviews.each do | review |%>
<% If current_user.already_reported? (Review)%>
  <% = link_to'Cancel report', recipe_review_reports_path (review), method:: delete%>
<% else%>
  <% = link_to'report', recipe_review_reports_path (review), method:: post%>
<% end%>
<% end%>


reports_controller.rb ↓

class ReportsController


Would you please tell me the solution?

  • Answer # 1

    reviews \ index.html.erb

    <% if current_user.already_reported? (Review)%>
    <% = link_to'Cancel report', recipe_review_reports_path (review, @ recipe.id), method:: delete%>
    <% else%>
    <% = link_to'report', recipe_review_reports_path (review, @ recipe.id), method:: post%>
    <% end%>


    It was solved by

Related articles