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

时间:2015-09-18 13:16:22

标签: ruby-on-rails ruby ruby-on-rails-4 spree spree-auth-devise

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

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>

我不知道它在哪里寻找&#39; societies_path&#39;因为我已经更新了app / views / spree / admin / societies / new.html.erb来查找&#39; admin_societies_path&#39;,这里是

<%= 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 %>

我也尝试删除链接到后面,但它再次给出同样的错误。

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

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

我怀疑_form partial

中的这一行
<%= form_for(@society) do |f| %>

你需要在这里引用命名空间,所以也许像

这样的东西
<%= form_for([:admin, @society]) do |f| %>

或添加您自己的网址

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