Как я могу извлечь значение из объекта? - PullRequest
0 голосов
/ 17 июля 2011
---
- !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

(http://pastebin.com/J1angM6d)

Как я могу получить значение post_id в виде массива? @arr = [ 5,6,3,7,1 ] Теперь я хочу получить эти сообщения с этим post_id. Это правильно? @p = Post.where(:id=>@arr)

1 Ответ

0 голосов
/ 17 июля 2011
@p = Post.find(my_collection.map(&:post_id))
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...