2015-12-21 33 views
0

我有一个Tictactoe游戏,我为我正在参加的课程做了一个,我的应用程序已部署到heroku。它在我的本地主机上正常工作,但是当我在线播放时,它不喜欢我使用的重定向。重定向到('/ status'),这是我要检查是否有胜利或平局,如果没有,它会让AI或第二位玩家选择一个方块。我该如何解决这个问题,或者如果有人能指点我一个很酷的链接。我现在看了一会儿,似乎无法找到它。在heroku上的sinatra应用程序重定向

post '/game' do 
choice = params[:choice].to_i 
player_marker = players.current_player() 

if play_board.square_available?(choice - 1) == true 
    play_board.board[choice - 1] = player_marker 
    redirect to('/status') 
else 
    erb :squares, :locals => {:p1 => players.player1, 
           :p2 => players.player2, 
           :invaild => "Hey #{players.current} #{choice} is already taken", 
           :message2 => "Please choose again.", 
           :current => players.current, 
           :board => play_board.board, 
           :type => players.type} 
    end 
end 

    2015-12-21T03:06:29.194376+00:00 app[web.1]: https://mmtictactoe.herokuapp.com /squares -> /style.css 
    2015-12-21T03:06:32.382665+00:00 heroku[router]: at=info method=POST path="/game" host=mmtictactoe.herokuapp.com request 
_id=b6b0abdb-783d-4111-99e4-244c1730179a fwd="75.89.86.120" dyno=web.1 connect=1ms service=18ms status=500 bytes=231 
    2015-12-21T03:06:32.361241+00:00 app[web.1]: NoMethodError - undefined method `to' for #<Sinatra::Application:0x007f05bd 
0dae20>: 
+0

'它不喜欢的redirects' - 你的意思是什么? –

+0

@WandMaker当它得到了重定向到我的代码状态页的时间点。它给我一个内部服务器错误。看着日志,它给了我一个未定义的方法来错误,当我在本地运行时,它不会得到它的错误,它完美地工作,这是日志https://mmtictactoe.herokuapp.com/squares->/style的片段。 css r]:at = info method = POST path =“/ game”host = mmtictactoe.he “75.89.86.120”dyno = web.1 connect = 1ms service = 18ms statu NoMethodError - undefined method'to'for#

+0

我还没有学习测试我的代码的前端只做了后端测试,所以我不能对它进行测试..... –

回答

3

redirect to在1.2西纳特拉在2011年推出了如果没有这个,您必须在Heroku的服务器上运行一个很老的版本西纳特拉的。

以一个look here for getting started with Heroku,并确保您的Gemfile有西纳特拉1.4.x的规定(在此答案的时间最晚):

gem 'sinatra', '~>1.4.0'               
+0

谢谢....刚刚学会了如何部署到heroku和我们使用的示例gemfile一定是旧的,因为它是1.1。 0长编辑它到一个最新的和presto!谢谢!!对于gem文件和proc文件仍然是新手 –

相关问题