0

I'm trying the following code however in the console it just returns the entire microposts array. I want to get the tag_list for each micropost that a user has posted.

As in I want User.find(1).microposts[0..-1].tag_list

User.find(1).microposts.each {|micropost| micropost.tag_list}

How can I get the tag_list for all posts?

Sorry for the noob question

2
  • I deleted my answer cause it was wrong. Good luck :) Commented Jul 25, 2013 at 3:57
  • @BenjaminSinclaire thanks for the taking time Commented Jul 25, 2013 at 6:59

2 Answers 2

2

Try this:

User.find(1).microposts.map(&:tag_list)
Sign up to request clarification or add additional context in comments.

Comments

1

Try with:

User.find(1).microposts.map(&:tag_list).flatten

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.