루비와 opensshift에 익숙하지 않아서 무엇을하고 있는지 잘 모르겠습니다.Ruby 정의되지 않은 메서드`[] 'for nil : 메서드 호출 전의 NilClass (NoMethodError)
루비 코드를 git으로 푸시하고 빌드를 시작하면이 오류가 발생합니다. NilClass (NoMethodError) :이 오류가 발생 후 내가 다시 올바른 평가를 얻고 있지만, 인터프리터는 정의되지 않은 메서드`[] '무기 호에 던지고 원인
remote: Building Ruby cartridge
remote: /var/lib/openshift/234325h2345234523452/app-root/runtime/repo/GetMovieRTRating.rb:23:in `Rating': undefined method `[]' for nil:NilClass (NoMethodError)
remote: from /var/lib/openshift/234325h2345234523452/app-root/runtime/repo/createCinemaTweets.rb:74:in `Run'
remote: from /var/lib/openshift/234325h2345234523452/app-root/runtime/repo/Driver.rb:5:in `<top (required)>'
remote: from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require'
remote: from /opt/rh/ruby193/root/usr/share/rubygems/rubygems/custom_require.rb:36:in `require'
remote: going to call rating 0 "Teenage%20Mutant%20Ninja%20Turtles", 2014
remote: Got the rating from the script: 22%
remote: going to call rating 1 "Teenage%20Mutant%20Ninja%20Turtles", 2014
remote: Got the rating from the script: 22%
remote: going to call rating 2 "The%20Maze%20Runner", 2014
remote: Got the rating from the script: 63%
remote: going to call rating 3 "The%20Maze%20Runner", 2014
remote: Got the rating from the script: 63%
remote: going to call rating 4 "The%20Maze%20Runner", 2014
remote: Got the rating from the script: 63%
remote: going to call rating 5 "Gone%20Girl", 2014
remote: An error occurred executing 'gear postreceive' (exit code: 1)
remote: Error message: CLIENT_ERROR: Failed to execute action hook 'build' for application
remote:
remote: For more details about the problem, try running the command again with the '--trace' option.
평가 방법이 작동 않습니다. 나는 이것이 다른 방법으로 돌지 않는 한 실패한 액션 훅 빌드를 일으키는 것으로 추정한다. 이 클래스
class Rotten
def Rating(movie="terminator", year=1984)
@rottenKey="<key>"
@movie = movie.gsub(/\"/i, '')
@requiredYear = year.to_i
@url = "http://api.rottentomatoes.com/api/public/v1.0/movies.json?q=#{@movie}&page_limit=50&apikey=#{@rottenKey}"
resp = Net::HTTP.get_response(URI.parse(@url))
data = resp.body
@i=0
@parsedData = JSON.parse(data)['movies']
while @i < 50 do
@foundYear = @parsedData[@i]['year'].to_i
@rating = @parsedData[@i]['ratings']['critics_score']
@i +=1
if @foundYear - @requiredYear == 0 then
return "#{@rating}%"
end
end
end
end
되고
을한다는 것이다 나는@rating = Rotten.new.Rating("#{@movieTitleURL}",@ratingYear)
감사
대부분의 변수에 @를 사용하는 이유가 있습니까? – tomsoft