Created
November 9, 2010 08:22
-
-
Save joeljunstrom/668856 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create | |
@my_thing = MyThing.create(params[:my_thing]) | |
respond_to do |format| | |
format.json { @my_thing.to_json } | |
end | |
end | |
$(document).ready(function() { | |
var $list = $('#list'), | |
$form = $('#my_form'); | |
$form.bind('submit', function(event) { | |
event.preventDefault(); | |
$.ajax({ | |
url: $form.attr('action')+'.json', | |
type: 'POST', | |
dataType: 'json', | |
data: $form.serialize(), | |
success: function(json) { | |
var obj = json['my_model_name']; | |
$list.append('<li>'+obj['name']+'</li>'); | |
$form.find(':input').each(function() { | |
switch(this.type) { | |
case 'password': | |
case 'select-multiple': | |
case 'select-one': | |
case 'text': | |
case 'textarea': | |
$(this).val(''); | |
break; | |
case 'checkbox': | |
case 'radio': | |
this.checked = false; | |
} | |
}); | |
} | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment