无法从rails中的helper模块访问lib中的类

时间:2017-01-05 05:42:23

标签: ruby-on-rails ruby

您好我正在使用rails app。在ArticlesHelper模块的函数makeRequestToAPI1中,我调用的是API1类(此类存在于lib /中)方法" createRequest(request)。但它给了我" NoMethodError"。

articles_helper.rb

ann: Array<any> = [
    {
      name: "ABC"
    },
    {
      name: "DEF"
    },
    {
      name: "ZZZ"
    }
];

api1.rb

require '././lib/ThirdPartyLibs/api1'
require '././lib/ThirdPartyLibs/api2'

module ArticlesHelper
    include  EnumsHelper

    def makeRequestToAPI1(request)
        # here as request to API is same as the original request
        # so I am directly passing the request to the API
        response = API1.createRequest(request)
        Rails.logger.debug "makeRequestToAPI1: #{response}"
    end

    def makeRequestToAPI2(request)
        requestToAPI2 = {}
        requestToAPI2.merge!({:items => request[:items]})
        requestToAPI2.merge!({:pickup => request[:pickup]})
        requestToAPI2.merge!({:drop => request[:drop]})

        #response = API2.createRequest(requestToAPI2)
        #Rails.logger.debug "makeRequestToAPI2: #{response}"
        end
end

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

您可以尝试将以下行添加到applicaion.rb

config.autoload_paths += %W(#{config.root}/lib)