覆盖ShopifyApp模块方法

时间:2016-10-10 19:48:28

标签: ruby-on-rails shopify ruby-on-rails-5

我试图覆盖ShopifyApp's new method,但不知道从哪里开始。基本上我需要添加另一个字段来获取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

要使用该模块,我会在控制器中执行以下操作:

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

但是没有地方可以使用它。如何以正确的方式解决这个问题?

1 个答案:

答案 0 :(得分:1)

重写是最重要的。如果没有任何prepend(您正在加载lib目录中的代码),以下内容将为您完成:

# 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
相关问题