路由中的 UrlGenerationError

UrlGenerationError within Routes

我有一个嵌套路由,但我收到缺少必需键的错误:[:product_id]。我正在通过 link_to 方法传递它,尽管它似乎不起作用

No route matches {:action=>"index", :controller=>"admin/merchandise/variants", :locale=>#<Product id: 7, name: "Latte", description: nil, product_keywords: [], product_type_id: 1, prototype_id: nil, permalink: "latte", available_at: nil, deleted_at: "2016-06-13 13:41:47", meta_keywords: "", meta_description: "", featured: false, description_markup: nil, brand_id: nil, created_at: "2016-06-13 13:41:47", updated_at: "2016-06-13 13:41:47">, :product_id=>#<Variant id: nil, product_id: 7, sku: nil, price: #<BigDecimal:7fb49c1cf540,'0.0',9(18)>, cost: #<BigDecimal:7fb49c1cf0b8,'0.0',9(18)>, master: false, deleted_at: nil, created_at: nil, updated_at: nil>} missing required keys: [:product_id]

HAML 模板

- title "New Variant (#{@product.name})"
= link_to "Back to Product", admin_merchandise_product_path(@product), class: 'button small'
= form_for @variant, :url  => admin_merchandise_product_variants_path(@product,@variant), :html => {:class => ''}  do |form|
  = render :partial => '/admin/merchandise/variants/form', :locals => {:form => form}
  .generic_submit_button
    = submit_tag "Create",  

路线

namespace :admin do
namespace :merchandise do
resources :products do
          member do
            get :add_properties
            put :activate
          end
          resources :variants
        end

我认为您应该从 form_for 中删除 @variant