Hi I am new to backbone and I understand that you essentially route javascript to HTML pages, but I cant seem to route any javascript to the application.html.erb since it doesnt have a specific URL.
I can solve this problem, by removing the HTML I want to work on and move it to the index page, but this really isnt what I want.
My "solution"
views/posts/post_index.js.coffee
class Poster.Views.PostsIndex extends Backbone.View
template: JST['posts/index']
events:
'click #new_post': 'createPost'
initialize: ->
@collection.on('reset', @render, this)
@collection.on('add', @appendEntry, this)
render: ->
$(@el).html(@template())
@collection.each(@appendEntry)
this
createPost: (event) ->
Backbone.history.navigate("/posts/new", true)
appendEntry: (post) ->
view = new Poster.Views.Post(model: post)
$('#posts_container').append(view.render().el)
index.jst.eco
<div id="menu_bar" class="jumbotron menu_bar row">
<div class="col-sm-2">
<button id="new_post" type="button" class="btn btn-default">Post</button>
</div>
<div class="col-offset-8 col-sm-2">
List
</div>
</div>
application.html.erbhas to do with anything. Your server is going to return an HTML page to bootstrap the Backbone application, then its up to your router and JavaScript initialization to get Backbone going and then its all up to Backbone and your templates.