Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read
Q&A

How to fetch single column for children? Question

+0
−0

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.

Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

0 comment threads

1 answer

+1
−0

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.

Why does this post require moderator attention?
You might want to add some details to your flag.

1 comment thread

not working properly (2 comments)

Sign up to answer this question »

This community is part of the Codidact network. We have other communities too — take a look!

You can also join us in chat!

Want to advertise this community? Use our templates!

Like what we're doing? Support us! Donate