Reputation: 14071
I've got a table of what I call resources, want to show in a jquery dialog a particular record when user clicks button in a row.
in the table I'm doing:
<td><%=button_to_function 'Show','showresource1()',:class =>"ui-button ui-state-default ui-corner-all", :id => resource.id %></td>
then in javascript I want to pass jQuery dialog the resource.id and open the dialog:
<script type="text/javascript" charset="utf-8">
function showresource1()
{
jQuery("#resource_details").load( 'http://localhost:3000/resources/show/4').dialog('open');
}
</script>
I can open the dialog and load this static URL, but am stumped re passing resource.id from the button_to_function down to the js function.
is button_to_function the right way to go and if so, how do I get URL defined in js?
Upvotes: 2
Views: 1523
Reputation: 736
It should be like code below
<% 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>
Upvotes: 1