0

我使用这样的脚手架创建了一个 Geddy 应用程序:

geddy gen app test
geddy gen secret
geddy gen scaffold project title:string description:string screenshot:string url:string

到目前为止一切正常,但我想编辑“添加”视图以将“屏幕截图”输入修改为“文件”输入。

form.html.ejs :

<div class="control-group">
  <label for="title" class="control-label">title</label>
  <div class="controls">
    <%- contentTag('input', project.title, {type:'text', class:'span6', name:'title'}) %>
  </div>
</div>
<div class="control-group">
  <label for="description" class="control-label">description</label>
  <div class="controls">
    <%- contentTag('input', project.description, {type:'text', class:'span6', name:'description'}) %>
  </div>
</div>
<div class="control-group">
  <label for="screenshot" class="control-label">screenshot</label>
  <div class="controls">
    <%- contentTag('input', project.screenshot, {type:'file', class:'span6', name:'screenshot'}) %>
  </div>
</div>
<div class="control-group">
  <label for="url" class="control-label">url</label>
  <div class="controls">
    <%- contentTag('input', project.url, {type:'text', class:'span6', name:'url'}) %>
  </div>
</div>

add.html.ejs :

<div class="hero-unit">
  <form id="project-form" class="form-horizontal" action="/projects" method="POST" enctype="multipart/form-data">
    <fieldset>
      <legend>Create a new Project</legend>
      <% if(params.errors) { %>
      <div class="control-group">
        <ul>
        <% for(var err in params.errors) { %>
          <li><%= params.errors[err]; %></li>
        <% } %>
        </ul>
      </div>
      <% } %>

      <%- partial('form', {project: {}}) %>

      <div class="form-actions">
        <%- contentTag('input', 'Add', {type: 'submit', class: 'btn btn-primary'}) %>
      </div>
    </fieldset>
  </form>
</div>

单击提交按钮时出现的错误:

Title: "title" is required..

我的控制器:

this.create = function (req, resp, params) {

  var self = this
    , project = geddy.model.Project.create(params);

  if (!project.isValid()) {
    this.respondWith(project);
  }
  else {
    project.save(function(err, data) {
      if (err) {
        throw err;
      }
      self.respondWith(project, {status: err});
    });
  }
};

“项目”对象为空...

4

0 回答 0