2011-11-27 3 views
0

많은 image_blog가있는 제품 요소가 있습니다.해당 ID에서보기의 연관 검색

나는 image_blog 아이디와 해당 image_blog가 포함 된 @product 아이디를 가지고 있습니다. 어떻게 접근 할 수 있습니까?

나는 @product.image_blogs[:id=>"24"]과 같아야합니다. 올바른 구문은 무엇입니까? 당신이 image_blog의 독특한 id을 알고 있기 때문에

답변

1

, 당신은 그것을 액세스 할 수 @product 필요하지 않습니다 : 액세스, 대답

ImageBlog.find(24) 

, 첫 image_blogid@product에서 :

@product.image_blogs.first.id 
1
@product.image_blogs.where(id:24) # ruby 1.9 new hash syntax 
@product.image_blogs.where(:id => 24) # previous hash syntax