2013-10-17 13 views
0

我想有以下鏈接:如何使用link_to,remote:true和jQuery將存儲在DOM中的數據傳遞給控制器​​?

<%= link_to image_tag("#{@player1.first_name}_#{@player1.last_name}.jpg", 
    alt: "#{@player1.first_name}_#{@player1.last_name}", class: "playerpic"), 
    updatepts_path, :remote => true %> 

的DOM內使用jQuery控制器提供數據,例如:在那裏我已經添加data: { matchupID: $('#matchup-id').data(matchupID)) }link_to幫手

<%= link_to image_tag("#{@player1.first_name}_#{@player1.last_name}.jpg", 
    alt: "#{@player1.first_name}_#{@player1.last_name}", class: "playerpic"), 
    updatepts_path, :remote => true, 
    data: { matchupID: $('#matchup-id').data(matchupID)) } %> 

。這是可能的嗎?如果是這樣,我將如何使用params[:data][:matchupID]訪問控制器中的數據?

謝謝!

回答

0

您可以向路由中的matchupID的updatepts_path添加參數,並將matchupid添加到由link_to創建的鏈接url。

如果您不介意亂七八糟的網址,那麼只需在鏈接中添加像matchupID = xxxx這樣的內容即可。

Aferall link_to只是在最後製作一個標籤,它完全能夠在渲染後由javascript操縱。

相關問題