3

我无法将我的控制器绑定到创建的管理员面板选项卡。我究竟做错了什么?

路线.rb

match '/admin/pimport', :to => 'spree/admin/pimport#index', :as => :pimport

覆盖/pimport_tab.rb

Deface::Override.new(
  :name => "pimport_tab",
  :virtual_path => "spree/layouts/admin",
  :insert_bottom => "[data-hook='admin_tabs'], #admin_tabs[data-hook]",
  :text => '<%= tab :pimport %>'
)

控制器/spree/admin/pimport_controller.rb

module Spree
  module Admin
    class PimportController < Spree::Admin::BaseController
      def index
      end
    end
  end
end

我的意见/狂欢/管理员/pimport/index.html.erb 是空白的。


http://localhost:3000/admin/pimport我收到此错误时:

NoMethodError in Spree/admin/pimport#index

它显示

/Users/artemaminov/.rvm/gems/ruby-1.9.3-p194@rails327spree/gems/spree_core-1.1.3/app/views/spree/layouts/admin.html.erb 

其中第 35 行提出:

undefined method `admin_pimport_path' for #  ActionDispatch::Routing::RoutesProxy:0x007f88d5aacca0>

提取的源代码(大约第 35 行):

<div id="admin-menu" data-hook>
  <ul data-hook="admin_tabs">
    <%= render :partial => 'spree/admin/shared/tabs' %>
    <%= tab(:promotions, :url => spree.admin_promotions_path) %><%= tab :pimport %>
  </ul>
  <br class="clear">
</div>
4

1 回答 1

0

在 routes.rb 中应该写:

Spree::Core::Engine.routes.prepend do
  match '/admin/pimport', :to => 'admin/pimport#index', :as => :pimport
end

或使用命名空间:

Spree::Core::Engine.routes.prepend do
  namespace :admin do
    match '/pimport', :to => 'pimport#index', :as => :pimport
  end
end
于 2012-08-14T21:38:47.453 回答