こんにちは、私の zend アプリケーションにバックボーン app/assets フォルダーを作成したい場合、どこに配置すればよいでしょうか? バックボーン アプリ フォルダーの構成Javascript,Stylesheets and Templates
簡単に言えば、これはバックボーンがレールでどのように機能するかです
routes.rb
resources :entries
エントリ/インデックス用の Rails コントローラ
class EntriesController < ApplicationController
respond_to :json
def index
respond_with Entry.all
end
end
これらのコードで URL が /entries にある場合、バックボーン コレクションは単純に理解されます
class Blog.Collections.Entries extends Backbone.Collection
url: '/entries'
バックボーン ルータで
class Blog.Routers.Entries extends Backbone.Router
routes:
'': 'index'
'entries/:id': 'show'
initialize: ->
@collection = new Blog.Collections.Entries()
@collection.fetch()
index: ->
view = new Blog.Views.EntriesIndex(collection: @collection)
#alert 'hi'
$('#container').html(view.render().el)
show: (id) ->
alert "Entry #{id}"
次にレンダリングしますBackbone.View
class Blog.Views.EntriesIndex extends Backbone.View
template: JST['entries/index']
initialize: ->
@collection.on('reset',@render,this)
render: ->
$(@el).html(@template(entries: @collection))
this
assets/templates/entries/index.jst.eco をレンダリングするためのテンプレート
<h1>Blog</h1>
<ul>
<% for entry in @entries.models: %>
<li><%= entry.get('name')%></li>
<% end %>
</ul>
最後に、assets/javascripts/blog.js.coffee でアプリを初期化します
window.Blog =
Models: {}
Collections: {}
Routers: {}
Views: {}
initialize: ->
new Blog.Routers.Entries()
Backbone.history.start()
$(document).ready ->
Blog.initialize()
上記の Backbone.js の MVC パターンは興味深いですが、Zend Framework で実装したいので、Rails で使用するように使用するには、どの構成を変更する必要がありますか?また、ビューをレンダリングするためのテンプレートをどのように処理しますか? ありがとう