我在 erb 模板中有一个 div,单击它时我想触发控制器的显示操作。
<div class = "box">
Content within the box
</div>
<script>
$(document).ready(function() {
$('.box').click(function(){
$.get(<%=hack_path(h) %>)
});
});
</script>
我收到错误“参数数量错误(0 代表 1)”。我想知道我是否在正确的轨道/模式上以达到预期的结果,还是应该使用其他技术?
这是实际的模板:
<h1>Hacks</h1>
<% @hack.each do |h| %>
<div class = "box">
<table>
<h3><%= h.hack_name %></b></h3>
<%= h.id %>
<span id = "showhack"> <%= link_to 'Show', hack_path(h) %></span>
<%= link_to 'Edit', edit_hack_path(h) %>
<%= link_to 'Destroy', hack_path(h), method: :delete, data: { confirm: 'Are you sure?' } %>
<%= link_to "Get Data", :controller => :admins, :action => :checkSerials, :method => :get %>
<% h.serials.each do |s| %>
<tr>
<th>Series Title</th>
<th>Series Name</th>
<th>Series Id</th>
<% s.observations.sort{|a,b| a.id <=> b.id}.last(5).each do |o| %>
<th><%= o.date %></th>
<% end %>
</tr>
<tr>
<td><%= link_to s.title, [h, s] %></td>
<td><%= s.series_name %></td>
<td><%= s.id %></td>
<% s.observations.sort{|a,b| a.id <=> b.id}.last(5).each do |o| %>
<% if s.units_short == 'Mil. of $' %>
<td><%= number_to_currency(convertMtoBHack(o.value), :precision => 0) %></td>
<% else %>
<td><%= number_to_currency(o.value, :precision => 0) %></td>
<% end %>
<% end %>
</tr>
<tr>
<td><%= s.frequency_short %></td>
<td><%= s.units_short %></td>
</tr>
<% end %>
</table>
</div>
<script>
$(document).ready(function() {
$('.box').click(function(){
$.get(<%= hack_path(@hack).to_json %>)
});
});
</script>
<div><%= link_to 'New Hack', new_hack_path %></div>