
Untitled
By: a guest on
Jul 4th, 2012 | syntax:
None | size: 0.91 KB | hits: 9 | expires: Never
better way to do html updates then to expose javascript in rails3
<script type="text/javascript">
// When DOM loads, init the page.
$(function() {
// Executes a callback detecting changes with a frequency of 1 second
$("#id_element_placeholder").observe_field(1, function( ) {
$.ajax({
type: "GET",
dataType: "json",
url: "/students/get/" + this.value,
success: function(data){
$('#last_name').attr('value', data.student.last_name);
$('#building').attr('value', data.student.building);
$('#room').attr('value', data.student.room);
}
});
});
});
</script>
def get
@student = Student.find(params[:id])
respond_to do |format|
format.html
format.json { render :json => @student }
end
end