如何只渲染相同日期的音符?

我们怎样才能每天只显示一个音符,而不是每天显示所有音符,而是音符的注释note.note_date == date

 Day 1: Notes/notes # Shows both Day 1 and Day 3 note. Only want to show Day 1 note Day 2: Notes/form Day 3: Notes/notes # Shows both Day 1 and Day 3 note. Only want to show Day 3 note Day 4: Notes/form Day 5: Notes/form 

挑战/节目

  Day      date %>   

注释/便签

    

票据/表格

    [:month, :day, :year] %>  

challenges_controller

 def show @notable = @challenge @notes = @notable.notes @note = Note.new end 

回顾一下,用户创建了一个挑战。 挑战具有days_challenged属性。 用户选择将被挑战的天数,即10,15,30等。对于每一天,将呈现notes/form 。 如果note.notes_date等于相应的一天,那么我们怎样才能显示一个音符代替notes/form

 <% if @notes.any? @today_notes = @notes.select{ |note| note.notes_date.strftime("%m/%d/%y") == date.strftime("%m/%d/%y") } %> <%= render 'notes/notes' %> <% else %> ... <% end %> 

然后在notes / notes partial中使用@today_notes

将此<%= render 'notes/notes' %>部分更改为低于1,并在note.html.erb文件下方。

挑战展示:

  <%= render partial: 'notes/notes', locals:{note: note} %> 

将note.html.erb重命名为下划线_notes.html.erb

笔记/ _notes.html.erb:

  <%= note.notes_text %>