2017-04-12 50 views
-1

顯示來自關聯表的圖片我有兩個表:試圖在Grails的

內容域看起來是這樣的,正在生成hotelId酒店和內容:

class Content { 

Hotel hotel 
String featuredImageUrl 

static constraints = { 
    featuredImageUrl nullable:true 
} 

我從上傳圖片到S3該酒店的顯示頁面到相關的內容表,這是工作 - 現在我想顯示這些圖像。

我覺得像這樣的工作,它不是:

<g:if test="${content.featuredImageUrl}"> 
    <img src="${content.featuredImageUrl}" /> 
</g:if> 
+1

是否不行?我沒有看到你的問題是什麼。 – erichelgeson

+0

不,它不起作用。我的問題是,如何顯示圖像? –

+0

「featuredImageUrl」屬性的內容是什麼,你可以直接嘗試加載它嗎?您的S3存儲桶是否具有爲這些圖像提供服務的權限? – erichelgeson

回答

0

當在GSP渲染的內容,您需要提供渲染對象,Grails的有沒有辦法知道你問哪些內容因爲 - 你必須提供它。

例子:

class SomeController { 
    def index() { 
     // Get the object/objects from your db somehow: 
     def content = Content.get(1) 

     // render your view with the given model/objects 
     // by default grails-app/views/controllername/actionname.gsp 
     render [content: content] 
    } 
} 

查看文檔 - 8.1.3模型和視圖中http://docs.grails.org/latest/guide/theWebLayer.html

+0

嗨,我擺弄你的解決方案,並不能得到它的工作。你是對的,我沒有很好地表達我的問題。讓我重述一下你誤會了你的意思。我想將我的內容表中的圖像顯示到相關酒店對象的顯示頁面(其中酒店= hotelId的內容ID)。 –

+0

我在正確的軌道上嗎? ---- def showContent() { def content = Content.findByHotelId(params.id) render [content:content] } –

+0

請提供錯誤或問題以及您嘗試過的內容。也許上傳一個完整的例子給github並且測試失敗會更容易調試。 – erichelgeson