2012-08-10 72 views
3

我遍歷電影集合在我的電影,像這樣:爲什麼Rails將'localhost:3000/assets'添加到我的圖像src中?

<li> 
    <%= link_to image_tag(movie.image.url), movie %> 
    <%= link_to sanitize(movie.title), movie %> 
</li> 

但它產生下面的HTML:

<img alt="3382" src="http://0.0.0.0:3000/assets/http//s3-eu-west-1.amazonaws.com/ramen-hut/pictures/3382.jpg?1344477777"> 

它把我難倒了,任何人都可以在這方面的幫助?爲什麼要加上http://0.0.0.0:3000/assets/的網址?

回答

3

因爲:在您的movie.image.url中的http之後失蹤。

沒有http://,Rails認爲這是一個資產名稱並添加了資產前綴。

例如:

<%= image_tag 'http//foo/bar.jpg' %> 
<%= image_tag 'http://foo/bar.jpg' %> 

輸出:

<img alt="Bar" src="/assets/http//foo/bar.jpg" /> 
<img alt="Bar" src="http://foo/bar.jpg" /> 
相關問題