我正在尝试在我的应用程序中创建评论,但是当我在控制器中执行以下操作时:
def create
@product = Product.find(params[:product_id])
@review = @product.reviews.create(params[:review])
redirect_to product_path(product)
end
我明白了Couldn't find Product without an ID
。我填写了表格,当它执行以下行时@product = Product.find(params[:product_id])
,它似乎无法找到产品
路线
resources :products do
resource :reviews
end
产品/show.html.erb
<%= form_for(@product.reviews.build) do |f| %>
<div class="field">
<%= f.label :title %>
<br/>
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :author %>
<br/>
<%= f.text_field :author %>
</div>
<div class="field">
<%= f.label :content %>
<br/>
<%= f.text_area :content %>
</div>
<div class="field">
<%= f.label :rating %>
<br/>
<%= f.number_field :rating %>
</div
<div class="actions">
<%= f.submit %>
</div>
<% end %>