Ruby on rails 未定义的方法`prepend';对于HTTP::客户端Gem
执行Ruby on rails 未定义的方法`prepend';对于HTTP::客户端Gem,ruby-on-rails,ruby,rubygems,httpclient,rake-task,Ruby On Rails,Ruby,Rubygems,Httpclient,Rake Task,执行call函数时,此模块中出现undefined method prepend错误。 我无法理解为什么它会给出错误,因为在我以前的rails版本4.2(现在是5.2)中,它工作得非常好 结束 Gemfile旧文件(工作) Gemfile新建(不工作) 你能分享你的rake任务代码吗?@RomanAlekseiev刚刚添加了代码你提供的代码不完整。你如何称呼这些方法?你能提供一份工作吗?另外,您的问题似乎表明,用于与以前版本的ruby和/或rails一起工作的代码。这是正确的吗?你以前用的是什么
call
函数时,此模块中出现undefined method prepend
错误。
我无法理解为什么它会给出错误,因为在我以前的rails版本4.2(现在是5.2)中,它工作得非常好
结束
Gemfile旧文件(工作)
Gemfile新建(不工作)
你能分享你的rake任务代码吗?@RomanAlekseiev刚刚添加了代码你提供的代码不完整。你如何称呼这些方法?你能提供一份工作吗?另外,您的问题似乎表明,用于与以前版本的ruby和/或rails一起工作的代码。这是正确的吗?你以前用的是什么版本?(您尚未提供的)是否在旧版本上运行?理想情况下,我们应该能够复制该行为,但目前您没有提供足够的信息供任何人进行复制,这是毫无疑问的。@TomLord以前的ruby版本是2.3.3,rails版本是4.2。@Sachin您仍然没有提供详细的信息。从您的代码中,我可以看到正在调用
SyncProjectJob.perform_later
,但是您没有显示SyncProjectJob
是如何定义的,也没有显示完整的错误消息。(这个例子不是最小的,因为复制问题不需要很多额外的代码;它也不完整,因为实际触发错误的关键代码缺失。)
NoMethodError: undefined method `prepend' for #<HTTP::Client:0x00005564644a0560>
module Awr
class Gateway
class Error < StandardError; end
def initialize(url:, token:)
@url = url
@token = token
end
def self.build
self.new(
url: ENV.fetch('AWR_API_URL'),
token: ENV.fetch('AWR_API_TOKEN')
)
end
def call(action_name,project:,**args)
response = get_operation(action_name).execute(
client: client,
url: url,
project: project,
**make_params(args)
)
interpret_response(response)
end
def get(url)
interpret_response(client.get(url))
end
def client
HTTP.follow(max_hops: 3)
end
def make_params(params)
params.merge(
token: token
)
end
private
attr_reader :url, :token
def interpret_response(response)
case response.status.code
when 200
response
else
raise_response_error(response)
end
end
def raise_response_error(response)
status = response.status
body = response.body
raise Error.new("#{status.reason} [#{status.code}] - #{body}")
end
def get_operation(key)
Operation[key]
end
end
end
class Operation
def initialize(action:,http_method:,project_key:,path:,**const_args)
@action = action
@http_method = http_method
@project_key = project_key
@path = path
@const_args = const_args
end
def execute(client:,url:,project:,**params)
client.prepend(http_method, full_url(url),
make_params(project,params))
end
def self.register(key,**args)
raise KeyError.new("#{key} operation already defined.") if
lookup.has_key?(key)
lookup[key] = new(**args)
end
def self.[](key)
lookup.fetch(key)
end
private
attr_reader :action,:http_method,:project_key,:path,:const_args
def full_url(url)
URI.join(url,path)
end
def make_params(project,params)
{
params: params.merge(
project_key => project,
action: action,
**const_args
)
}
end
def self.lookup
@lookup ||= {}
end
def self.reset
@lookup = {}
end
end
http (2.0.0)
httpclient (2.8.3)
httpi (2.4.2)
http (4.4.1)
httpclient (2.8.3)
httpi (2.4.4)