没有路由匹配缺少的必需键:[object_id]

No route matches missing required keys: [object_id]

我的应用程序中有几个嵌套路由。我正在建立一个数据库,根据初创公司所在的行业以及该行业内的各种竞争对手对初创公司进行分类。

我一直在寻找这个错误的答案,但一直找不到答案:

编辑 添加了完整的错误消息和 categories_controller.rb

错误信息:

ActionController::UrlGenerationError in Categories#show

No route matches {:action=>"edit", :controller=>"categories", :id=>"5", :industry_id=>nil} missing required keys: [:industry_id]

嵌套路由: 资源 :industries , 仅: [:show, :create, :edit, :update] do 资源:类别做 资源:初创公司,模块::类别
结尾 结束

Category.rb

class Category < ActiveRecord::Base
    has_many :startups, as: :startupable
    belongs_to :industry
    belongs_to :user
end


Industry.rb

class Industry < ActiveRecord::Base
    belongs_to :user
    has_many :categories
end

startup.rb

class Startup < ActiveRecord::Base
    belongs_to :startupable, polymorphic: true
    belongs_to :user
end

c

ategories_controller.rb

class CategoriesController < ApplicationController
  before_action :set_category, only: [:show, :edit, :update, :destroy]
  respond_to :html

  def index
    @categories = Category.all.order("created_at DESC").paginate(:page => params[:page], :per_page => 3)
    authorize @categories
  end

  def show
  end


  def new
    @industry = Industry.find(params[:industry_id])
    @category = @industry.categories.new
    flash[:notice] = "Category created."
    authorize @category
  end


  def edit
  end


  def create
    @industry = Industry.find(params[:industry_id])
    @category = current_user.categories.build(category_params)
    respond_with @industry
    authorize @category
  end


  def update
    respond_to do |format|
      if @category.update(category_params)
        format.html { redirect_to @category, notice: 'Category was successfully updated.' }
        format.json { render :show, status: :ok, location: @category }
      else
        format.html { render :edit }
        format.json { render json: @category.errors, status: :unprocessable_entity }
      end
    end
  end


  def destroy
    @category.destroy
    redirect_to @industry
    flash[:notice] = "You have succesfully deleted the category."
  end

  private
    def set_category
      @category = Category.find(params[:id])
      authorize @category
    end
    def correct_user
      @category = current_user.categories.find_by(id: params[:id])
      redirect_to categories_path, notice: "Not authorized to edit this Category" if @category.nil?
    end

    def category_params
      params.require(:category).permit(:name)
    end
end

出于某种原因,我在点击 查看 按钮时没有调用 Industry_id,或者我的类别没有与他们的行业正确关联。

有什么建议吗?

show.html.erb

更新

<%= link_to "Edit", edit_industry_category_path(@category.industry, @category) %>