Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 4th, 2012  |  syntax: None  |  size: 0.91 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. better way to do html updates then to expose javascript in rails3
  2. <script type="text/javascript">
  3.  
  4.     // When DOM loads, init the page.
  5.     $(function() {
  6.       // Executes a callback detecting changes with a frequency of 1 second
  7.       $("#id_element_placeholder").observe_field(1, function( ) {                                      
  8.         $.ajax({
  9.         type: "GET",
  10.         dataType: "json",
  11.         url: "/students/get/" + this.value,
  12.         success: function(data){
  13.             $('#last_name').attr('value', data.student.last_name);
  14.             $('#building').attr('value', data.student.building);
  15.             $('#room').attr('value', data.student.room);                                                
  16.         }
  17.         });
  18.       });
  19.     });
  20.  
  21.   </script>
  22.        
  23. def get
  24.     @student = Student.find(params[:id])
  25.     respond_to do |format|
  26.         format.html
  27.         format.json { render :json => @student }
  28.      end
  29. end