Rails Spree Extension doesn't show instance in view

153 Views Asked by At

The default Spree Commerce has "Categories" and "Brand" taxonomies. I have generated an extension that creates a custom testing page where the taxonomies are displayed, but in reverse order. This is only for practicing purposes.

The custom testing page "/testing" seems to be routing correctly and using the view testing.html.erb, but I can not load the taxonomies instance defined in the method. It gives me an undefined method each for nil:NilClass.

Note: I'm working in the extension only, not in the spree app.

spree_custom_extension/controllers/spree/home_controller_extension.rb

module Spree
  HomeController.class_eval do
    def testing
      @taxonomies = Spree::Taxonomy.includes(root: :children).reverse_order
    end
  end
end

spree_custom_extension/views/spree/home/testing.html.erb

<% @taxonomies.each do |taxonomy| %>
  <%= taxonomy.name %><br>
<% end %>

spree_custom_extension/config/routes.rb

Spree::Core::Engine.routes.draw do
  get '/testing' => 'home#testing'
end
0

There are 0 best solutions below