0
我有一個產品元素有很多image_blog。從視圖中檢索關聯
我有一個image_blog id和一個包含該image_blog的@product
。我怎樣才能訪問它?
我想它應該看起來像@product.image_blogs[:id=>"24"]
。什麼是正確的語法?
我有一個產品元素有很多image_blog。從視圖中檢索關聯
我有一個image_blog id和一個包含該image_blog的@product
。我怎樣才能訪問它?
我想它應該看起來像@product.image_blogs[:id=>"24"]
。什麼是正確的語法?
既然你知道image_blog
的獨特id
,你不需要@product
訪問它:
ImageBlog.find(24)
要訪問,比方說,第一image_blog
的id
在@product
:
@product.image_blogs.first.id
@product.image_blogs.where(id:24) # ruby 1.9 new hash syntax
@product.image_blogs.where(:id => 24) # previous hash syntax