Spree::Admin::Societies#new undefined method `societies_path' 中的 NoMethodError

NoMethodError in Spree::Admin::Societies#new undefined method `societies_path'

我是 rails 上的 spree 和 ruby 的新手。在我的 spree 应用程序中创建自定义控制器时,我可以使用 deface 在 spree 管理面板中成功添加 link 到它。但是当我转到那个link时,它给了我以下错误

NoMethodError in Spree::Admin::Societies#new
Showing app/views/spree/admin/societies/_form.html.erb where line #1 raised:
undefined method `societies_path' for #<#<Class:0x007f19cb636898>:0x007f19c5ecacf8>

我不知道它从哪里寻找 'societies_path',因为我已经更新了 app/views/spree/admin/societies/new.html.erb 以寻找 'admin_societies_path',这里是

<%= render 'form' %>
<%= link_to 'Back', admin_societies_path %>

和app/views/spree/admin/societies/_form.html.erb包含

    <%= form_for(@society) do |f| %>
     <% if @society.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(@society.errors.count, "error") %> prohibited this society from being saved:</h2>
      <ul>
      <% @society.errors.full_messages.each do |message| %>
        <li><%= message %></li>
      <% end %>
      </ul>
    </div>
  <% end %>

  <div class="field">
    <%= f.label :name %><br>
    <%= f.text_field :name %>
  </div>
  <div class="field">
    <%= f.label :address %><br>
    <%= f.text_field :address %>
  </div>
  <div class="field">
    <%= f.label :area %><br>
    <%= f.text_field :area %>
  </div>
  <div class="field">
    <%= f.label :postcode %><br>
    <%= f.number_field :postcode %>
  </div>
  <div class="field">
    <%= f.label :city %><br>
    <%= f.text_field :city %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
    <% end %>

我也尝试删除 link 以返回,但它再次给出相同的错误。

config/routes.rb 是

mount Spree::Core::Engine, :at => '/'
Spree::Core::Engine.add_routes do
 namespace :admin do
    resource :societies
  end
end

我的 app/controllers/spree/admin/societies_controller.rb 是

module Spree
 module Admin
 class SocietiesController < Spree::Admin::BaseController
  before_action :set_society, only: [:show, :edit, :update, :destroy]

  def index
    @societies = Society.all
  end

  def show
  end

  def new
    @society = Society.new
  end

  def edit
  end

  def create
    @society = Society.new(society_params)

    respond_to do |format|
      if @society.save
        format.html { redirect_to @society, notice: 'Society was successfully created.' }
        format.json { render :show, status: :created, location: @society }
      else
        format.html { render :new }
        format.json { render json: @society.errors, status: :unprocessable_entity }
      end
    end
  end
  def update
    respond_to do |format|
      if @society.update(society_params)
        format.html { redirect_to @society, notice: 'Society was successfully updated.' }
        format.json { render :show, status: :ok, location: @society }
      else
        format.html { render :edit }
        format.json { render json: @society.errors, status: :unprocessable_entity }
      end
    end
  end

  def destroy
    @society.destroy
    respond_to do |format|
      format.html { redirect_to societies_url, notice: 'Society was successfully destroyed.' }
      format.json { head :no_content }
    end
  end

  private
    def set_society
      @society = Society.find(params[:id])
    end

    def society_params
      params.require(:society).permit(:name, :url, :building_number, :address, :area, :postcode, :city, :active, :IsDelete)
    end
end
end
end

如有任何帮助,我们将不胜感激。

我怀疑是_form partial中的这一行

<%= form_for(@society) do |f| %>

您需要在此处引用命名空间,所以可能是

<%= form_for([:admin, @society]) do |f| %>

或添加您自己的 url

<%= form_for(@society, url: admin_societies_path) do |f| %>