2011-01-30 110 views
0
<%= link_to "", { :controller => 'board', 
          :action => 'take_turn', 
          :id => @board.id, 
          :x => col, 
          :y => row }, :remote => true do %> 

产生:Ruby on rails3:Link_to无法正常工作?

<a href="" action="take_turn" controller="board" id="15" x="0" y="1"> 
      <div class="ttt_square"> 
       &nbsp; 
      </div> 
</a> 

为什么不工作的权利?它应该生成

回答

1

您应该添加括号权与你的方式就可以得到它,就像这样:

<%= link_to({:controller => 'board', 
         :action => 'take_turn', 
         :id => @board.id, 
         :x => col, 
         :y => row }, :remote => true) do %> 
    <div class="ttt_square"> 
      &nbsp; 
    </div> 
<% end %> 

否则解释器不能理解哪个是正确的参数 希望这有助于

3

这是因为您正在使用块版本link_to。在这种情况下,第一个参数应该是URL,而不是空白字符串。

+0

我得到语法错误,意外tASSOC,期待'当我摆脱了e空字符串。 = \ – NullVoxPopuli 2011-01-30 22:10:57

+1

将`link_to`的参数也包含在圆括号中。 – 2011-01-30 22:12:54

2
<%= link_to board_take_turn_path(@board, :x => col, :y => row) , :remote => true do %> 
# Your code and stuff here 
<% end %> 

我觉得应该工作(你需要确保board_take_turn_path实际上是定义