[Solidus 3.2.2] Hello Everyone, I'm doing a fork o...
# support
s
[Solidus 3.2.2] Hello Everyone, I'm doing a fork of the
Spree::Admin::ImagesController
but I get the error
AbstractController::ActionNotFound (The action 'index' could not be found
Indeed by looking in Spree:Admin:ImagesController and Spree:Admin:ResourceController I don't find a index function, I wonder where and how the index action is defined ?
βœ… 1
r
Hi Sabo πŸ‘‹ I agree that the index action hasn’t been defined in both the controllers, but I think the
images#index
route is available due to the current route definition here: https://github.com/solidusio/solidus/blob/v3.2.2/backend/config/routes.rb#L42-L46 (here is an example of all the routes created through a
resources
definition) Is it possible that you are unintentionally trying to perform the index action in your fork?
s
Hello @rainer thank you for the response I had intentionnally trying to perform the index action, the goal is for the fork to reproduce the same behavior than
images#index
I (think) understand how the roads are made, but I don't understand how the index action of
Spree::Admin::ImagesController
work because it's not defined neither in ImagesController nor in ResourceController For the "fork" in my route.rb I have:
Copy code
namespace :admin do
    resources :kits do
      resources :images, controller: 'images_kit' do
        post :update_positions, on: :collection 
      end
    end 
  end
and
Copy code
admin_kit_images   GET   /admin/kits/:kit_id/images(.:format)   spree/admin/images_kit#index
Perhaps because I changed the controller name to '_images_kit'_ (the fork) the view in admin/images/index is not found ?
r
Perhaps because I changed the controller name to β€˜_images_kit’_ (the fork) the view in admin/images/index is not found ?
Yes I think you are right πŸ‘ I quickly tried to remove the admin/images/index.html.erb and I got the same exception, you may need to try adding a dedicated admin/images_kit/index.html.erb view in your scenario
πŸ‘ 1
s
Yes, it's "working" now I have the error:
Copy code
NameError in Spree::Admin::ImagesKitController#index
uninitialized constant Spree::ImagesKit
Copy code
Extracted source (around line #280)
    # unknown.
    def constantize(camel_cased_word)
      Object.const_get(camel_cased_word)
    end

activesupport (7.0.4) lib/active_support/inflector/methods.rb:280:in `const_get'
r
There is a
model_class
method in `Spree:Admin:ResourceController`: https://github.com/solidusio/solidus/blob/v3.2.2/backend/app/controllers/spree/admin/resource_controller.rb#L144-L146 In your case, starting from the controller name,
model_class
is probably trying to constantize
"Spree::ImagesKit"
. If you want to continue using the
Spree::Image
model, in your
Spree::Admin::ImagesKitController
you can override the
model_class
method with something like this:
Copy code
private

def model_class
  Spree::Image
end
πŸ™Œ 1
s
Thank you @rainer it's working like a charm ;)
πŸ™Œ 1