在将变量传递给客户端时遇到一些问题。运行的任务是这样的:
def getmaps
$mapnames_current = []
url = 'http://s3-ap-northeast-1.amazonaws.com/splatoon-data.nintendo.net/stages_info.json'
resp = Net::HTTP.get_response(URI.parse(url))
buffer = resp.body
result = JSON.parse(buffer)
result.each do |gamemode|
gamemode['stages'].each do |stage|
$mapnames_current << $mapnames.key(stage['id'])
end
end
end
并$mapnames_current
在这里被调用:
<div class="text-center">
<h2>Current Maps!</h2>
<h3>Turf War:</h3>
<h2>{{ $mapnames_current[0] }}</h2>
<h2>{{ $mapnames_current[1] }}</h2>
<h3>Ranked:</h3>
<h2>{{ $mapnames_current[2] }}</h2>
<h2>{{ $mapnames_current[3] }}</h2>
</div>
我不确定这里出了什么问题。$mapnames_current
变量不应该在任何地方都可以访问吗?