2013-12-20 41 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