2013-12-20 42 views
1

這是我的文件夾:節點快速失敗負荷CSS和JS

/app 
    └── models 
     └── ... 
    └── node_module 
     └── ... 
    └── routes 
     └── ... 
    └── public 
     └── css 
     └── js 
    └── views 
     └── unites 
      └── new.js 
      └── show.js 
      └── edit.js 

所以,當我去// mysiteweb /新我的日誌是這樣的:

GET /maitre-unites-new 304 4ms 
GET /css/bootstrap.css 304 3ms 
GET /js/bootstrap.js 304 2ms 

但是,當我去上// mysiteweb /顯示我的日誌是這樣的:

GET /maitre-unites-show/52b46d81ddd1086615000001 304 2ms 
GET /maitre-unites-show/css/bootstrap.css 404 2ms 
GET /maitre-unites-show/js/bootstrap.js 404 1ms 
GET /maitre-unites-show/images/unites/batiment1.jpeg 404 2ms 

我不明白爲什麼,我的語法是一樣的:

/* 
* GET New unit. 
*/ 
    app.get('/maitre-unites-new', ensureAuthenticated, function (req, res){ 
     Unites.find({}, function (err, unites) { 
     res.render('unites/new', { 
      unites: unites, 
      user : req.user, 
      title : ' Que voulez vous créer Maitre Du Jeu' 
     }); 
     }); 
    }); 
/* 
* GET show unit. 
*/ 

    app.get('/maitre-unites-show/:id', ensureAuthenticated, function (req, res){ 
     Unites.findById(req.params.id, function (err, unites) { 
     res.render('unites/show', { 
      unites: unites, 
      user : req.user, 
      title : ' Que voulez vous créer Maitre Du Jeu' 
     }); 
     }); 
    }); 

我的看法news.js:

<% layout('layout') -%> 
<% script('js/bootstrap.js') -%> 
<% stylesheet('css/bootstrap.css') -%> 

     <!-- Jumbotron --> 
     <div class="jumbotron"> 
      <h1><%= title + ' ' %><code><%= user.username %></code></h1> 
      <p style="text-align:center;">Ho Créateur ! Inventez-nous comme toutes choses en cet univers.</p> 
      <p> 
      <a href="/maitre-aide" class="btn btn-primary btn-lg">aide &raquo;</a> 
      <a href="/maitre-de-jeu" class="btn btn-primary btn-lg">retour &raquo;</a> 
      </p> 
     </div> 

     <div class="row"> 
     <div class="col-md-12"> 
      <h3>Créez une Unité:</h3> 
      <form method='post' action='/maitre-unites-new'> 

      <div> 
      <label>Nom:</label> 
      <input type="text" name="name"/><br/> 
      </div> 

      <div> 
      <label>Avatar:</label> 
      <input type="text" name="avatar"/><br/> 
      </div> 

      <div> 
       <label>Description:</label> 
       <textarea name="description" row="5" cols="50"></textarea> 
      </div> 

      <hr> 
      <%= unites.name %> 

       <h2>Inclure d'autres unités dans celle-ci:</h2> 
      <% if (unites && unites.length !=0) { %> 
       <div> 
        <% for (var index in unites) { %> 
        <input type="checkbox" name="<%= unites[index].unit %>" value="<%= unites[index]._id %>"> <%= unites[index].name %> | 
        <% } %> 
       </div> 
      <% } else { %> 
       <div> 
       no document exist 
       </div> 
      <% } %> 

      <hr> 

       <h2>Inclure cette unité dans d'autres unités:</h2> 
      <% if (unites && unites.length !=0) { %> 
       <div> 
        <% for (var index in unites) { %> 
        <input type="checkbox" name="<%= unites[index].unit %>" value="<%= unites[index]._id %>"> <%= unites[index].unit %> | 
        <% } %> 
       </div> 
      <% } else { %> 
       <div> 
       no document exist 
       </div> 
      <% } %> 


      <input type="submit" value="Save"> 
      </form> 
     </div> 
     </div> 

     <!-- Site footer --> 
     <div class="footer"> 
     <p>&copy; Company 2013</p> 
     </div> 

    </div> <!-- /container --> 

我的看法show.js:

<% layout('layout') -%> 
<% script('js/bootstrap.js') -%> 
<% stylesheet('css/bootstrap.css') -%> 

     <!-- Jumbotron --> 
     <div class="jumbotron"> 
     <h1><%= title + ' ' %><code><%= user.username %></code></h1> 
     <p style="text-align:center;">Ho Créateur ! Inventez-nous comme toutes choses en cet univers.</p> 
      <p> 
      <a href="/maitre-aide" class="btn btn-primary btn-lg">aide &raquo;</a> 
      <a href="/maitre-de-jeu" class="btn btn-primary btn-lg">retour &raquo;</a> 
      </p> 
     </div> 

     <div class="row"> 
     <div class="col-md-12"> 
      <%= unites.name %> 
      <img src="images/unites/<%= unites.avatar %>.jpeg"> 
      <%= unites.description %> 
     </div> 
     </div> 

     <!-- Site footer --> 
     <div class="footer"> 
     <p>&copy; Company 2013</p> 
     </div> 

    </div> <!-- /container --> 

這是我repo.git 爲什麼我得到這個/領班 - 聯信秀/圖像。 ...而不是/圖像...?

+0

你是否爲公共/靜態文件聲明瞭一個靜態文件夾?例如像「app.use(express.static(__ dirname +'/ public'));」在你的應用程序? – ztirom

+0

是 app.set('views',__dirname +'/ views'); app.set('view engine','ejs'); app.engine('ejs',require('ejs-locals')); (express.static(path.join(__ dirname,'public'))); –

+0

您需要展示您的觀點。 – punund

回答

0

好的。

new  -> /
show -> /maitre-unites-show/ 

所有你需要:該錯誤是由你的show路線有額外的路徑組件/:id,所以它們從當前的URL,這是不同的搜索你的看法路線是相對的,造成的事實做的是讓你的路徑絕對在視圖中:

<% layout('layout') -%> 
<% script('/js/bootstrap.js') -%> 
<% stylesheet('/css/bootstrap.css') -%> 
+0

我不能在其他方面修復它? –

+0

首先謝謝。 –

+0

否則有很多方法可以解決這個問題,但是如果最簡單且基本正確的解決方案不能令人滿意,那麼您必須在某些限制條件下工作,這對我們來說是未知的。 – punund