【问题标题】:Redirects with a sinatra app on heroku使用 Heroku 上的 sinatra 应用程序重定向
【发布时间】:2015-12-21 14:43:46
【问题描述】:

我为我正在学习的课程制作了一个 Tictactoe 游戏,我将我的应用程序部署到了 heroku。它在我的本地主机上运行良好,但是当我在线播放它时,它不喜欢我使用的重定向。重定向到('/status'),这是我要检查是否有胜利或平局的地方,如果没有,它会让 ai 或第二名玩家选择一个正方形。我该如何解决这个问题,或者是否有人可以将我指向一个很酷的链接。我现在找了一段时间,似乎找不到它。

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>:

【问题讨论】:

  • it doesn't like the redirects - 你的意思是什么?
  • @WandMaker 当它得到重定向到我在代码中的状态页面的时间点时。它给了我一个内部服务器错误。查看日志,它给了我一个未定义的错误方法,我在本地运行它时没有得到它,当我在本地播放它时它工作得很好这是日志的 sn-p 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 - #<:app> 的未定义方法 `to'
  • 我还没有学会测试我的代码的前端只做了后端测试所以我不能只做一个测试.....
  • 最好将日志 sn-p 添加到您的问题中,以便人们知道您面临的问题是什么

标签: ruby heroku sinatra


【解决方案1】:

redirect to 是在 2011 年在 Sinatra 1.2 中引入的。如果您没有这个,您必须在 Heroku 服务器上运行一个非常旧版本的 Sinatra。

获取look here for getting started with Heroku,并确保您的 Gemfile 指定了 Sinatra 1.4.x(本回答时的最新版本):

gem 'sinatra', '~>1.4.0'                                                          

【讨论】:

  • 谢谢 .... 刚刚学会了如何部署到 heroku 并且我们使用的示例 gemfile 一定是旧的,因为它是 1.1.0 将其更改为最新的并且 presto !!!谢谢!! gem 文件和 proc 文件还是新手
猜你喜欢
  • 1970-01-01
  • 2012-01-14
  • 1970-01-01
  • 1970-01-01
  • 2012-04-11
  • 2015-03-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多