2011-01-30 108 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實際上是定義