如何使用link_to、remote:true和jQuery将存储在DOM中的数据传递给控制器?

如何使用link_to、remote:true和jQuery将存储在DOM中的数据传递给控制器?,jquery,ruby-on-rails,ajax,Jquery,Ruby On Rails,Ajax,我希望有以下链接: <%= link_to image_tag("#{@player1.first_name}_#{@player1.last_name}.jpg", alt: "#{@player1.first_name}_#{@player1.last_name}", class: "playerpic"), updatepts_path, :remote => true %> 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 %>
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,
    data: { matchupID: $('#matchup-id').data(matchupID)) } %>
true,
数据:{matchupID:$('#matchupID')。数据(matchupID))}%>
其中,我已将
数据:{matchupID:$('#matchupID').data(matchupID))}
添加到
链接到
帮助程序。这是可能的吗?如果是这样,我将如何使用
params[:data][:matchupID]
从控制器访问数据


谢谢

您可以为routes中的matchupID向updatepts_路径添加一个参数,并将matchupID添加到由link_创建的链接url中

如果你不介意凌乱的url,那就在链接中添加?matchupID=xxxx之类的内容

一般来说,link_最终只是制作了一个标记,它完全可以在渲染后由javascript进行操作