Ruby on rails 如何从对象中提取值?

Ruby on rails 如何从对象中提取值?,ruby-on-rails,Ruby On Rails,如何获取post_id作为数组的值? @arr=[5,6,3,7,1] 现在我想用这个post\u id获取那些帖子。 这是正确的吗? @p=Post.where:id=>@arr问这个问题是否正确,你只需试一下就可以回答。你告诉我们,它有用吗?它做了你想让它做的事吗?如果你曾经尝试过,但没有成功,那么你有一个更好的问题可以向人们提出。正如蒂洛所说,在任何人回答你的问题之前,你需要开始接受答案 --- - !ruby/object:Comment attributes: post_i

如何获取post_id作为数组的值? @arr=[5,6,3,7,1] 现在我想用这个post\u id获取那些帖子。 这是正确的吗?
@p=Post.where:id=>@arr

问这个问题是否正确,你只需试一下就可以回答。你告诉我们,它有用吗?它做了你想让它做的事吗?如果你曾经尝试过,但没有成功,那么你有一个更好的问题可以向人们提出。正如蒂洛所说,在任何人回答你的问题之前,你需要开始接受答案
---
- !ruby/object:Comment
  attributes:
    post_id: '5'
  changed_attributes: {}
  previously_changed: {}
  attributes_cache: {}
  marked_for_destruction: false
  destroyed: false
  readonly: false
  new_record: false
- !ruby/object:Comment
  attributes:
    post_id: '6'
  changed_attributes: {}
  previously_changed: {}
  attributes_cache: {}
  marked_for_destruction: false
  destroyed: false
  readonly: false
  new_record: false
- !ruby/object:Comment
  attributes:
    post_id: '3'
  changed_attributes: {}
  previously_changed: {}
  attributes_cache: {}
  marked_for_destruction: false
  destroyed: false
  readonly: false
  new_record: false
- !ruby/object:Comment
  attributes:
    post_id: '7'
  changed_attributes: {}
  previously_changed: {}
  attributes_cache: {}
  marked_for_destruction: false
  destroyed: false
  readonly: false
  new_record: false
- !ruby/object:Comment
  attributes:
    post_id: '1'
  changed_attributes: {}
  previously_changed: {}
  attributes_cache: {}
  marked_for_destruction: false
  destroyed: false
  readonly: false
  new_record: false
@p = Post.find(my_collection.map(&:post_id))