Чувак, это плохой код (
Чтобы исправить текущий вариант:
прежде всего <% = notes = @notes_hash ['id'] || []%> будет выводить значение примечания только в сценарии, поэтому зафиксируйте его как <% notes = @notes_hash ['id'] || []%>
Далее вы инициализируете переменную notes каждый раз, когда нажимаете ссылку .notebook, поэтому удалите ее из текущей процедуры:
<div id="notes-list">
</div>
<script type="text/javascript">
(function() {
<% notes = @notes_hash['id'] || [ ] %>
var notes = <%= notes.collect{ |a| a.id }.to_json %>
$(".notebook-link").click(function() {
var id = $(this).getAttribute("data");
$("#notes-list").html(notes[id]); # notes[id] is just an object, you will probably wants to render it someway e.g. with JQ templates
});
})()
</script>
Другой способ сделать это - просто отобразить скрытые div с сгруппированными заметками, а подпрограмма onClick просто покажет соответствующий div:
<div id="notebooks-list">
<% @notebooks.each do |notebook| %>
<%= link_to notebook.description, "#", {:class => "notebook-link",
:remote => true, :data => notebook.id.to_json }%>
<% end %>
</div>
<% @notes_hash.each_pair do |nh_id, notes| %>
<div class="notes-list hidden" data="<%= nh_id %>">
<ul>
<% notes.each do |note|
<li><%= note. description %></li>
<% end %>
</ul>
</div>
<% end %>
<script type="text/javascript">
$(".notebook-link").click(function() {
$(".notes-list").hide().filter("[data=\"" + $(this).attr("data") + "\"]").show()
});
</script>