3
votes

I can't bind my controller to the created admin's panel tab. What am I doing wrong?

routes.rb

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

overrides/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 %>'
)

controllers/spree/admin/pimport_controller.rb

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

and my views/spree/admin/pimport/index.html.erb is blank.


At http://localhost:3000/admin/pimport I get this error:

NoMethodError in Spree/admin/pimport#index

It's showing

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

where line #35 raised:

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

Extracted source (around line #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
What version of Spree did you use?thekingoftruth

1 Answers

0
votes

In routes.rb should write:

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

or using namespace:

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