spree gem rails中的NameError(未初始化的常量...)

时间:2015-11-01 06:54:53

标签: ruby-on-rails ruby ruby-on-rails-4 ruby-on-rails-3.2

我定义了一个控制器: 热潮/管理/ payment_members_controller.rb

module Spree
  module Admin
    class PaymentMembersController < ResourceController
      def index
      end 
    end
  end
end

在文件config / routes

Spree::Core::Engine.routes.append do
  namespace :admin do
    resources :payment_members
  end
end

路线:

admin_payment_members_path  GET  /admin/payment_members(.:format)   spree/admin/payment_members#index
                            POST /admin/payment_members(.:format)   spree/admin/payment_members#create
new_admin_payment_member_path   GET /admin/payment_members/new(.:format)    spree/admin/payment_members#new
edit_admin_payment_member_path  GET /admin/payment_members/:id/edit(.:format)   spree/admin/payment_members#edit
admin_payment_member_path   GET /admin/payment_members/:id(.:format)    spree/admin/payment_members#show
                            PATCH   /admin/payment_members/:id(.:format)    spree/admin/payment_members#update

当我到达网址&#34; http://localhost:3000/admin/payment_members&#34; (索引)在浏览器中: 在控制台中:

Processing by Spree::Admin::PaymentMembersController#index as HTML
NameError (uninitialized constant Spree::PaymentMember):
  activesupport (4.1.6) lib/active_support/inflector/methods.rb:253:in `const_get'
  activesupport (4.1.6) lib/active_support/inflector/methods.rb:253:in `block in constantize'
  ..........

请告诉我,如何修复此错误?

1 个答案:

答案 0 :(得分:1)

根据您在before_filter中使用ResourceController的控制器名称尝试load the resource。你创建了Spree:: PaymentMember吗?

我建议您创建Spree::PaymentMember(app / models / spree / payment_member.rb)或覆盖load_resource中的PaymentMembersController方法。