Ad

Override ShopifyApp Module Method

- 1 answer

I'm trying to override ShopifyApp's new method but not sure where to start. Basically I need to add another field to get a params:

/lib/shopify_app/sessions_concern/new.rb:

module ShopifyApp
  module SessionsConcern
    module New
      def new
        if params[:field] == "abc"
         authenticate if params[:shop].present?
        end # or else ...
      end
    end
  end
end

To use that module, I would do something like this in a controller:

ShopifyApp::SessionsConcern.prepend ShopifyApp::SessionsConcern::New

But there's no where to use that. How to go about this the correct way?

Ad

Answer

Overriding is overriding. The following would do it for you without any prepending (having that you are loading the code from lib directory):

# lib/shopify_monkeypatching.rb
module ShopifyApp
  module SessionsConcern
    def new
      if params[:field] == "abc"
       authenticate if params[:shop].present?
      end # or else ...
    end
  end
end
Ad
source: stackoverflow.com
Ad