Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 4 如何在Rails 4中防止Post被重定向_Ruby On Rails 4 - Fatal编程技术网

Ruby on rails 4 如何在Rails 4中防止Post被重定向

Ruby on rails 4 如何在Rails 4中防止Post被重定向,ruby-on-rails-4,Ruby On Rails 4,我有一个小网站,建立了一个选择的链接 <td><a id="participant_link" href="" data-method="POST">Add</a></td> 然后将其激发到具有以下路径的操作: create_new_participation POST /participations/create_new/:player_id /:tournament_id(.:format) participations#crea

我有一个小网站,建立了一个选择的链接

<td><a id="participant_link" href="" data-method="POST">Add</a></td>
然后将其激发到具有以下路径的操作:

create_new_participation POST  /participations/create_new/:player_id /:tournament_id(.:format)      participations#create_new
哪个代码是:

def create_new
  @player = Player.find(params[:player_id])
  @tournament = Tournament.find(params[:tournament_id])
  @tournament.players << @player

  redirect_to "/tournaments/#{@tournament.id}/edit",status: :see_other
end
使用GET方法

问题是我得到了:

没有路线匹配[发布]“/tournaments/7/编辑”

我以前使用过PUT,它可以工作,但是我已经清理了站点代码(从表中删除表单和其他标记,查找散乱的标记,诸如此类的东西),它停止了工作。 我已经读到,这篇文章是无法重定向的,但你瞧,它被重定向了。我尝试使用
状态
进行重定向,但也没有成功


你知道为什么会发生这种情况吗?该怎么做才能让它停止?我知道我可以让锦标赛#edit接受GET和PUT,但这将是一个丑陋的修复,不是一个正确的解决方案。

问题在于jquery,它只有在更改作为选择框的#参与者后才触发。如果没有它,链接是空的,因此它通过post操作路由到自身。

显然,您的路由出了问题<代码>编辑比赛获取/比赛在我看来不合适。您是否介意提供您的
路由.rb
?另外,
部分重定向到“/tournaments/{@tourbant.id}/edit”
似乎您没有使用
edit_tourban@tourban
风格的rails构建路由,@D-side指出,问题最有可能在于您的路由定义(您是否使用
资源
)?是的,我使用它。问题是,直到我更改微调器后,jquery才启动。很抱歉占用您的时间,我在发布问题后才找到答案,而不是几天前。
def create_new
  @player = Player.find(params[:player_id])
  @tournament = Tournament.find(params[:tournament_id])
  @tournament.players << @player

  redirect_to "/tournaments/#{@tournament.id}/edit",status: :see_other
end
edit_tournament GET    /tournaments/:id/edit(.:format)  tournaments#edit