Rails Javascript - 点击

时间:2017-03-27 07:59:04

标签: javascript ruby-on-rails-3

在我的项目中,我在视图中称之为部分

game_player_main.html.erb:

<%= button_to "Wurfbild", home_player_statistic_detail_path(:game_id => @game.id, :player_id => @player.id, :home_or_away => @home_or_away, :player_mode => 'GoalArea'), class: 'btn_submit', :remote => true %>

player_statistic_detail.js.erb:

$("#player_statistic_detail").html("<%= escape_javascript render(partial: 'home/player_statistic_detail.html.erb', :handlers => [:erb]) %>");

一切正常。在我的局部视图中,我有一个画布字段。通过单击此字段,它应重新加载通过click事件的x坐标和y坐标的部分。

这是我的代码:

_player_statistic_detail.html.erb:

<script>

var canvas = createHiDPICanvas(350, 228);
var ctx = canvas.getContext("2d");
canvas.addEventListener("mousedown", doMouseDown, false);

function doMouseDown(event) {
  canvas_x = event.pageX;
  canvas_y = event.pageY;

  canvas_x -= canvas.offsetLeft;
  canvas_y -= canvas.offsetTop;

  $("#player_statistic_detail").html("<%= escape_javascript render(partial: 'home/player_statistic_detail.html.erb', :handlers => [:erb]) %>");

}

如果我只是将javascript命令复制到我的视图中,我收到错误:

  

ActionView :: Template :: Error(堆栈级别太深)

是否可以刷新我的部分player_statistic_detail.html.erb并传递坐标?

1 个答案:

答案 0 :(得分:0)

一种可能的解决方案可能是:

var url = "url...";
  console.log("URL: " + url);
  $.ajax(url);