2014-09-25 43 views
0

我可以在ActiveAdmin中成功創建一篇文章,並且我可以成功上傳圖片以便與之一起使用。現在,我的問題是,雖然「Post#show」動作會告訴我圖像的路徑,但我希望這也是一個鏈接。爲了清楚起見,我在下面列出了我正在談論的內容。上傳到ActiveAdmin中的Post對象的圖像鏈接?

enter image description here

在最底部領域,很明顯,該圖像上傳成功。 ActiveAdmin甚至告訴我在哪裏可以找到它,但它給我的路徑是簡單的文本。我希望它能夠鏈接到該圖片。有沒有簡單的_path功能,我忘了?

回答

1

最簡單的方法是剪裁Post模型的顯示頁面。這也就是Customizing the Show Screen

ActiveAdmin.register Post do 
    show do 
    attributes_table_for resource do 
     row :id 
     row :title 
     row :slug 
     # ... 
     row :image do 
     span link_to(resource.image.path, resource.image) 
     span img(src: resource.image.path) 
     end 
    end 
    end 
end 

官方ActiveAdmin文檔中描述的另一種方法,我認爲是有可能是延長ActiveAdmin的默認AttributesTable component處理您的圖像屬性。

+0

這是一個巨大的幫助!謝謝!現在,你知道如何在圖像下直接添加圖像路徑嗎?我知道我可以通過在塊下添加另一個'row:image'來實現,但是有沒有辦法在'row:image do ... end'塊內執行? – elersong 2014-09-26 17:28:24

+0

@elersong更新了我的答案,增加了一個範圍來顯示圖像。請參閱http://www.activeadmin.info/docs/12-arbre-components.html#text_node – baxang 2014-09-29 01:51:09