2012-02-06 39 views
0

我正在使用我的第一個Rails應用程序,並且無法讓我的圖像文件(logo.png)在localhost:3000/pages/home頁面的瀏覽器中顯示。該圖像保存在我的Rails應用程序的public/images/logo.png文件中。任何想法爲什麼它可能不會顯示?在Rails應用程序中不顯示圖像

下面是代碼:

application.html.erb

<!DOCTYPE html> 
<html> 
    <head> 
     <title><%= title %></title> 
    <%= csrf_meta_tag %> 
    <!--[if lt IE 9]> 
    <script src="http://html5shiv.googlecode.com/svn/trunk/trunk/html5.js"></script> 
    <![endif]--> 
    <%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %> 
    <%= stylesheet_link_tag 'blueprint/print', :media => 'print' %> 
    <!--[if lt IE 8]><%= stylesheet_link_tag 'blueprint/ie' %><![endif]--> 
    <%= stylesheet_link_tag 'custom', :media => 'screen' %> 
     </head> 
     <body> 
      <div class="container"> 
       <header> 
        <%= image_tag("logo.png", :alt => "Sample App", :class => "round") %> 
        <nav class="round"> 
         <ul> 
          <li><%= link_to "Home", '#' %></li> 
          <li><%= link_to "Help", '#' %></li> 
          <li><%= link_to "Sign in", '#' %></li> 
         </ul> 
        </nav> 
       </header> 
       <section class="round"> 
        <%= yield %> 
       </section> 
      </div> 

      </div>  
     </body> 
</html> 

添加源在容器中:

<div class="container"> 
       <header> 
        <img alt="Sample App" class="round" src="/images/logo.png" /> 
        <nav class="round"> 
         <ul> 
          <li><a href="#">Home</a></li> 
          <li><a href="#">Help</a></li> 
          <li><a href="#">Sign in</a></li> 
         </ul> 
        </nav> 
       </header> 
       <section class="round"> 


     <h1>Sample App</h1> 
     <p> 
      This is the home page for the 
      <a href="http://railstutorial.org">Ruby on Rails Tutorial</a> 
      sample application. 
     </p> 

     <a href="#" class="signup_button round">Sign up now!</a> 

       </section> 
      </div> 

      </div> 

回答

0

你需要指定一個像 「/圖片鏈接/logo.png「 或者如果更頻繁地使用圖像,還有創建短路徑規則的方法

+0

嗯...我只是改變了路徑「/images/logo.png」,然後點擊「刷新」在瀏覽器中沒有任何事情發生。有什麼建議麼? TIA – pdenlinger 2012-02-06 18:22:40

+0

你...你看到你的HTML輸出...有沒有標籤呢?如果有的話,src鏈接到什麼地方? – bernabas 2012-02-06 18:26:29

+0

是的,有一個圖片標籤,並且來源指向「images/logo.png」。我已經從上面的容器div的代碼中粘貼了一個新的編輯。 TIA – pdenlinger 2012-02-06 18:32:56

0

在常規視圖,您可以訪問圖像公共/資產/ images目錄是這樣的:

<%= image_tag "rails.png" %> 
相關問題