사용자가 링크를 클릭하여 다른 열에 표시 할 때마다 특정 노트에서 노트 제목을 검색하려고합니다. 제발 루비/레일에서 여전히 초보자입니다. 내 index.html.erb 분명히해시에서 수집하고 html로 표시하는 RoR
<div id="notebooks-list">
<% @notebooks.each do |notebook| %>
<%= link_to notebook.description, "#", {:class => "notebook-link",
:remote => true, :data => notebook.id.to_json }%>
<% end %>
</div>
<div id="notes-list">
<script type="text/javascript">
$(".notebook-link").click(function() {
var id = this.getAttribute("data");
<%= notes = @notes_hash['id'] || [ ] %>
var notes = <%= notes.collect{ |a| a.id }.to_json %>
$("#notes-list").html(notes);
});
</script>
</div>
, 잘못된 메신저하고 뭔가 내 static_controller.rb
def index
@user = current_user
@notebooks = @user.notebooks
@notes_hash = @user.notes.group_by(&:notebook_id)
respond_to do |format|
format.html
format.js
end
end
에서
.
당신이'내부 script' 태그를 작성하는 이유는'div'가 의도하는 것은 대체 .. 'script' 태그가 대체되면서 처음에는 작동하지 않고 다음 번에는 작동하지 않을 것입니다. – rubyprince
감사합니다. 지금 편집 할 것입니다. 편집 : 실제로, div id를 표시하려고했는데, div 안에 javascript가 있어도 몇 번의 클릭으로 작동했습니다. –
괜찮아요 .. 그래서 div.now에 표시하려고하는 당신은 div의 내용으로 노트 레코드의 ID의 배열을 보내고 있습니다. – rubyprince