Spree管理面板中的自定义选项卡

时间:2012-08-14 21:08:46

标签: ruby-on-rails ruby spree

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

的routes.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 %>'
)

控制器/礼包/管理/ pimport_controller.rb

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

我的观点/ spree / admin / 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>

1 个答案:

答案 0 :(得分: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