2015-10-26 62 views
0

我附加了圖像,它被稱爲圖標它有三種形式的原始,中等&拇指。 我想在JBuilder中json生成器中使用回形針的導軌

使用拇指網址,而不是原來的這是在模型

has_attached_file :icon, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png" 

index.json.jbuilder這裏:icon拇指聲明返回完整的圖像的我怎麼能修改URL它返回拇指網址

json.array!(@brands.visible) do |brand| 
    json.extract! brand, :id, :name, :position, :visible, :permalink, :counter, :description, :icon 
end 

,這裏是在控制器的動作

def index 
    @brands = Brand.all.sorted 
    end 

回答

1

因爲您需要將參數:thumb傳遞給icon,所以不能使用extract!。您需要單獨添加icon屬性:

json.array!(@brands.visible) do |brand| 
    json.extract! brand, :id, :name, :position, :visible, :permalink, :counter, :description 
    json.icon brand.icon.url(:thumb) 
end 
+0

它的工作完全謝謝你 – amronrails