Routing troubles with custom admin-view

66 views
Skip to first unread message

Simon Prückl

unread,
Jul 24, 2015, 10:23:58 AM7/24/15
to Spree
Hey there,

I'm having some troubles with my routes and hope, somebody can help me.
In my shop I need some additional configuration pages in the backend.

For example, I would like to be able to manage something called "Ingredient".
I've created: 
  • Ingredients in the database, the table is called "ingredients"
  • A model called Ingredient, located in app/model/spree/ingredient.rb.
  • Views for showing, editing and deleting ingredients.
  • A deface to add the link to the configurations_menu in the admin view.
  • The routes for the resource admin

No, when I try to load any admin page, I get this error:

undefined method `admin_ingredients_path' for #<ActionDispatch::Routing::RoutesProxy:0x007f85e8dc35a0>


My routes.rb:
Rails::application.routes.draw do  
  mount
Spree::Core::Engine, :at => '/'
 
namespace :admin do

    resources
:ingredients
   
end
end

The routes that are created:

simon@Ubuntu-1404-trusty-64-minimal:~/spiceshop$ rake routes | grep ingred
    admin_ingredients GET    
/admin/ingredients(.:format)          admin/ingredients#index
                      POST  
/admin/ingredients(.:format)          admin/ingredients#create
 new_admin_ingredient GET    
/admin/ingredients/new(.:format)      admin/ingredients#new
edit_admin_ingredient GET    
/admin/ingredients/:id/edit(.:format) admin/ingredients#edit
     admin_ingredient GET    
/admin/ingredients/:id(.:format)      admin/ingredients#show
                      PATCH  
/admin/ingredients/:id(.:format)      admin/ingredients#update
                      PUT    
/admin/ingredients/:id(.:format)      admin/ingredients#update
                      DELETE
/admin/ingredients/:id(.:format)      admin/ingredients#destroy

The deface:
Deface::Override.new(virtual_path:  "spree/admin/shared/sub_menu/_configuration",
                     name
:          "ingredients_admin_configurations_menu",
                     insert_bottom
: "[data-hook='admin_configurations_sidebar_menu'], #admin_configurations_sidebar_menu[data-hook]",
                     text
:          "<%= configurations_sidebar_menu_item Spree.t(:ingredients), spree.admin_ingredients_path %>",
                     disabled
:      false)

When I played with my routes.rb I got it working for a minute, but when I had to restart the web server, I had no more routes at all...
But I think that shows, that database, model, controller and views are working.
I think it has to do something with the routes.rb, whether it says Rails::application.routes.draw or Spree::something

Any help appreciated, thank you!
Message has been deleted

Simon Prückl

unread,
Jul 24, 2015, 6:07:56 PM7/24/15
to Spree, pru...@gmail.com
I thought I solved it by changing routes.rb to:

Rails::application.routes.draw do
  mount
Spree::Core::Engine, :at => '/'


 
Spree::Core::Engine.routes.prepend do


   
namespace :admin do
      resources
:ingredients
   
end
 
end
end

But that only works until the next server-restart, then I have to comment out the line
 Spree::Core::Engine.routes.prepend do
to start the server, after starting I can uncomment it again and the link in the configuration menu is working again...

Mohammed Gharbi

unread,
Jul 27, 2015, 6:48:33 AM7/27/15
to Spree, pru...@gmail.com
Simon, can you try this?


Rails
::application.routes.draw do
  mount 
Spree::Core::Engine, :at => '/'


  
Spree::Core::Engine.routes.draw do


    
namespace :admin do
      resources 
:ingredients
    
end
  
end
end

Simon Prückl

unread,
Jul 29, 2015, 10:56:08 AM7/29/15
to Spree, mgha...@gmail.com
Awesome, that tiny little changed solved it.

Thank you Mohammed!

Kaspar Tint

unread,
Aug 9, 2017, 11:38:57 AM8/9/17
to Spree, pru...@gmail.com
What is the difference between draw and prepent? Is there any perf impact?
Reply all
Reply to author
Forward
0 new messages