【发布时间】:2016-05-03 20:42:11
【问题描述】:
除了每天显示所有笔记,我们如何每天只显示一个笔记,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
挑战/表演
<% @challenge.dates_challenged.first(@challenge.days_challenged).each_with_index do |date, i| %>
Day <%= i + 1 %>
<% if @notes.any? { |note| note.notes_date.strftime("%m/%d/%y") == date.strftime("%m/%d/%y") } %>
<%= render 'notes/notes' %>
<% else %>
<%= render 'notes/form', :date => date %>
<% end %>
<% end %>
笔记/笔记
<% @notes.each do |note| %>
<%= note.notes_text %>
<% end %>
笔记/表格
<%= form_for [@notable, @note] do |f| %>
<%= f.text_area :notes_text, placeholder: 'Enter Recap' %>
<%= f.date_select :notes_date, selected: date, :order => [:month, :day, :year] %>
<% end %>
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?
【问题讨论】:
-
您能解释一下为什么您提出的解决方案不起作用吗?是否可以提供错误消息或不正确的输出?编辑问题比在 cmets 中回复要好。谢谢!
-
嗨@MichaelGaskill。我没有提出解决方案。我解释了我所拥有的,每个音符都用
notes/notes呈现。我不希望每一个音符都被渲染。我只想注意,等于date将在相应的日期呈现
标签: ruby-on-rails ruby