I just watched the backbone.js railscasts and Im not getting the error alert when the name is not present but do get an error on the server side.
im using rails 3.2.8 and backbone-on-rails 0.9.2.3
In the network console it does state that theres an error with the api/entries, and in the response theres the errors key, but still no alert when I click add with nothing on the form.
This is my code... please help me figure out what could be wrong!
class Raffler.Views.EntriesIndex extends Backbone.View
template: JST['entries/index']
events:
'submit #new_entry': 'createEntry'
'click #draw': 'drawWinner'
initialize: ->
@collection.on('reset', @render)
@collection.on('add', @appendEntry)
render: =>
$(@el).html(@template())
@collection.each(@appendEntry)
this
appendEntry: (entry) =>
view = new Raffler.Views.Entry(model: entry)
@$('#entries').append(view.render().el)
drawWinner: (event) ->
event.preventDefault()
@collection.drawWinner()
createEntry: (event) ->
event.preventDefault()
attributes = name: $('#new_entry_name').val()
@collection.create attributes,
wait: true
success: -> $('#new_entry')[0].reset()
error: @handleError
handleError: (entry, response) ->
if response.status == 422
errors = $.parseJSON(response.responseText).errors
for attribute, messages of errors
alert "#{attribute} #{message}" for message in messages
Thank you!