2011-07-17 53 views
0
--- 
- !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)

+0

无需-1虽然 – corroded

+0

问,如果这是正确的,你可以通过简单地尝试它自己回答的问题。你告诉我们,它工作吗?它做你想做的事吗?如果你尝试过它并没有奏效,那么你有更好的问题来打击人们。正如Thilo所说,你需要在任何人回答你的问题之前开始接受答案 –

+0

@corroded不是我:) – Thilo

回答

0
@p = Post.find(my_collection.map(&:post_id))