How to fetch single column for children? Question
How to get specific children's column? For questions, I can use @post.last_edited_at
or, something just like this. But, I was thinking to fetch a single column for all child.
<% post.children.last_edited_at do |last_edited| %>
<span>last_edited</span>
<% end %>
But, this isn't correct way to fetch single column for all child. I can fetch child's all column but, not a single one. I was thinking to put those strings inside an array. But, there's no possible way to put those value in array either. If I split using "
than, what if user is using quotation mark in body.
<% children.each do |answer| %>
I can fetch all columns above way but....
I am working on post.rb models.
1 answer
If I understand you correctly, you want to get the last_edited_at
column for every child post, i.e. a list of last edit dates?
For this you should use
post.children.map(&:last_edited_at)
which is a shorthand for
post.children.map { |c| c.last_edited_at }
which iterates over the list of children and maps each to its last_edited_at
timestamp.
0 comment threads