I am trying to generate a modal for each of my posts so that each post has a modal containing the post content(and eventually comments). When the comment link is clicked the modal will appear. The thing is I have to create a bootstrap modal block for each post so i decided it would be easiest to do this in my backbone template. Why isn't this working?
Here is my code:
app/assets/templates/posts/index.jst.eco
<% for post in @posts.models: %> <tbody><td> <%= post.get('content') %> </td></tbody> <tr><td> <a href="#<%= post.get('id') %>">Comment</a> </td></tr> <div class="modal" id="post-<%= post.get('id')%>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-header"> <%= post.get('content') %> </div> </div> <% end %>
app/assets/javascripts/routers/posts_router.js.coffee
class Voice.Routers.Posts extends Backbone.Router routes: '': 'index' ':id': 'show' initialize: -> @collection = new Voice.Collections.Posts() @collection.fetch() index: -> view = new Voice.Views.PostsIndex(collection: @collection) $('#container').html(view.render().el) show: (id) -> $("#post-#{id}").modal('show')
There are no errors in the js console, the modals just don't seem to appear. each post has a modal block with an html id field equal to "post-(the posts id)"
Any help is much appreciated!