I am using gem 'backbone-on-rails' #https://github.com/meleyal/backbone-on-rails and I am trying to create a "new quote" view, with a blank form. Should be very simple. :S But all I get is this error:
Uncaught ReferenceError: description is not defined By debugging the error appears to happen on the View->render method.
This is the code:
Router:
class SpencerGrafica.Routers.Quotes extends Backbone.Router
routes:
'new' : 'newQuote'
newQuote: ->
new SpencerGrafica.Views.NewQuote model: new SpencerGrafica.Models.Quote
View:
class SpencerGrafica.Views.NewQuote extends Backbone.View
el: '#app'
template: JST["quotes/new"]
initialize: ->
@render()
render: ->
$(@el).html(@template(@model.toJSON()))
@
Model
class SpencerGrafica.Models.Quote extends Backbone.Model
defaults:
description: null
Template
<form id="new-quote" name="quote">
<div>
<input type="text" name="description" value="<%= description %>" placeholder="Descripcion interna">
</div>
<div class="actions">
<input type="submit" value="Add Post" />
</div>
</form>
Any help REALLY appreciated. :)
model.toJSON()to the template, but in the template you are looking for a variable nameddescription. It's likely that what you want in the template is actuallymodel.description. Try that and see if it works. If that's not the issue make sure that description is something that exists on your model. - DigTheDoug@model.toJSON()should be returning{description: null}unless something (such as backbone-on-rails) has changed the defaulttoJSONbehavior; Rails would want to see{quote: { description: ... }}so I'd look at what backbone-on-rails is doing. So I wonder whatconsole.log(@model.toJSON())has to say insiderender. - mu is too shortconsole.log(@model.toJSON())like this:render: -> console.log(@model.toJSON()) $(@el).html(@template(quote: @model))I get this:Object {description: null}- tomasbarrios