ruby-on-railsspreedeface

Spree custom admin tab helper url on deface override


I'm building a custom tab on spree 2.1 and I have this on my Deface override which works fine, but when I try to click on my tab being already on this tab it goes to the url /admin/admin/places. So I need this to go always to /admin/places.

Found this https://codeclimate.com/github/spree/spree/Spree::Admin::NavigationHelper and it says that the tab take the first argument and make the path admin_places_path.

:insert_after => "[data-hook='admin_tabs']",
:text         => "<%= tab :places, :icon => 'icon-th-large'%>"

I tried the usually :url param with 'admin/places' but got the same result and was looking for the tab implementation which led me to the codeclimate and now here. Anyone know how to avoid this ?


Solution

  • That's how I solved:

     :text => "<%= tab :places, :icon => 'icon-th-large', url: main_app.admin_places_path %>"
    

    Searching for my answer I found that my routes for places were inside my app namespace not in the spree.

    namespace :admin do
      # Directs /admin/products/* to Admin::ProductsController
      # (app/controllers/admin/products_controller.rb)
      resources :places
    end
    

    So, to access the path I had to put "main_app." before the path targeted. See here: Adding Routes to Rails' Spree E-Commerce

    Looking the codeclimate code I saw that the url param was set as destination and could use that to put the "main_app." before the path and now is working.

    Edit:

    Found it a better way to do it.

    Routes

     Spree::Core::Engine.routes.prepend do
       namespace :admin do
       # Directs /admin/products/* to Admin::ProductsController
       # (app/controllers/admin/products_controller.rb)
       resources :places
       end
     end
    

    Moved all my folders(controllers and views) from controllers/views>places to controllers/views>spree>admin>places

    Removed the "my_app." and now it works better and easier.