0

私は 2 つのファイルを持っています: 更新: コード全体でファイルを更新したので、テンプレートが使用されていない理由がわかるかもしれません。多分私は何かが足りない。このビューを持つ script.js.coffee (Backbone.js を使用):

 window.Book = Backbone.Model.extend(url: ->
    (if @id then "/books/" + @id else "/books")
  )

  Router = Backbone.Router.extend(routes:
    "": "home"
    new: "editBook"
    "edit/:id": "editBook"
  )


  Books = Backbone.Collection.extend(model: Book)
  books = new Books()
  books.url = "books.json"



  BooksView = Backbone.View.extend(
    el: ".books"
    render: ->
      books = new Books()
      books.fetch success: =>
        template = _.template($("#book-list-template").html(),
          books: books.models
        )
        @$el.html template
        console.log template
  )

そして別のファイル index.html.erb

このテンプレートを持っている:

<div id="main">
<h1>Books list</h1>
<div class="books"></div>
 <script type="text/template" id="book-list-template">
    <a href="#new" class="btn btn-primary">New Book</a>
    <table class="table striped">
      <thead>
        <tr>
          <th>Title</th>
          <th>Author</th>
          <th>Year</th>
          <th></th>
         </tr>
       </thead>
       <tbody>
        <%% _.(books).each(function(book) { %>
          <tr>
            <td><%%= book.title  %></td>
            <td><%%= book.author  %></td>
            <td><%%= book.year  %></td>
            <td><a href="#/edit/<%%= book.id %>" class="btn">Edit</a></td>
          </tr>
        <%% }); %>
       </tbody>
     </table>
  </script>  

</div>

しかし、何も表示されません(エラーも発生しません)。私にとっては、コーヒーファイルがテンプレートの場所を認識できないようです それがどこにあるかを簡単に表示する方法はありますか?または、何か不足していますか?

PS Rails 4を使用しています

4

1 に答える 1