2012-02-22 51 views
4

我正在使用rails 3.0。 在我看来,我想与每一行复选框的表,并与特定参数的onclick事件函数至极的轨道变在check_box_tag的onclick函数中传递rails变量

<table> 
    <% @joueurs.each do |joueur| %> 
<tr> 
<td> 
<%= check_box_tag(joueur.id,joueur.id, false, :onclick=>"addPlayerToField(<%= joueur.gch %>,<%= joueur.drt %>);")%> 
</td> 
... 
</tr> 
<% end %> 
</table> 

我尝试了很多方法,我并没有实现对做到这一点。我知道joueurs.gch变量不是空的,并存在beacaus我在我看来在别处使用它。

我想产生类似:

<table> 
    <tr> 
<td> 
<input id="2036" name="2036" onclick="addPlayerToField(12, 13);" type="checkbox" value="2036"/> 
</td> 
    </tr> 
     <tr> 
<td> 
<input id="2037" name="2037" onclick="addPlayerToField(22, 10);" type="checkbox" value="2036"/> 
</td> 
    </tr> 
    </table> 

回答

6

我想你也许想是这样的:

<%= check_box_tag(joueur.id, joueur.id, false, :onclick=>"addPlayerToField(#{joueur.gch}, #{joueur.drt});")%> 
+0

宾果,你是男人。我在任何网站上都注意到这个符号。你怎么知道的?谢谢 – psic 2012-02-22 18:58:50

+0

这是Ruby内置的字符串插值。您可以在[Ruby编程](http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#Interpolation)中阅读它。 – Veraticus 2012-02-22 19:12:47

+0

宾果游戏可以帮助我:) – 2012-04-04 06:20:07