Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在使用Rails按钮到函数时向js函数传递一个值_Javascript_Jquery_Ruby On Rails - Fatal编程技术网

Javascript 在使用Rails按钮到函数时向js函数传递一个值

Javascript 在使用Rails按钮到函数时向js函数传递一个值,javascript,jquery,ruby-on-rails,Javascript,Jquery,Ruby On Rails,我有一个我称之为资源的表,当用户单击一行中的按钮时,我想在jquery对话框中显示一条特定的记录 在我正在做的表格中: <td><%=button_to_function 'Show','showresource1()',:class =>"ui-button ui-state-default ui-corner-all", :id => resource.id %></td> “ui按钮ui状态默认ui角点全部”,:id=>resource.i

我有一个我称之为资源的表,当用户单击一行中的按钮时,我想在jquery对话框中显示一条特定的记录

在我正在做的表格中:

<td><%=button_to_function 'Show','showresource1()',:class =>"ui-button ui-state-default ui-corner-all", :id => resource.id %></td>
“ui按钮ui状态默认ui角点全部”,:id=>resource.id%>
然后在javascript中,我想将resource.id传递给jQuery对话框并打开该对话框:

<script type="text/javascript" charset="utf-8">
  function showresource1()
  {
    jQuery("#resource_details").load( 'http://localhost:3000/resources/show/4').dialog('open');    
  }
</script>

函数showresource1()
{
jQuery(“#资源_详细信息”).load('http://localhost:3000/resources/show/4)。对话框(“打开”);
}
我可以打开对话框并加载这个静态URL,但是我无法将resource.id从button_to_函数重新传递到js函数


按钮功能正确吗?如果正确,我如何在js中定义URL?

应该与下面的代码类似

<% for res_id in ids %>
<%=button_to_function "Show", "show_resource('#{res_id}')" %>
<% end %>

<script type="text/javascript" charset="utf-8">
  function show_resource(res_id)
  {
    jQuery("#resource_details").load( 'http://localhost:3000/resources/show/' + res_id).dialog('open');
  }
</script>

功能显示资源(资源id)
{
jQuery(“#资源_详细信息”).load('http://localhost:3000/resources/show/“+res_id).对话框('open');
}