Advertisement
Guest User

Untitled

a guest
Mar 31st, 2015
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. class Visual < ActiveRecord::Base
  2.  
  3. establish_connection :vtest
  4.  
  5. self.table_name = 'employee'
  6.  
  7.  
  8. Visual.inheritance_column = 'inheritance_type'
  9.  
  10. belongs_to :user
  11.  
  12. def emp_matches(x)
  13. (x.id.to_i == self.id.to_i ? true : false)
  14. end
  15. end
  16.  
  17. class UserController < ApplicationController
  18.  
  19.  
  20. def populate_form
  21.  
  22. @visual = Visual.find_by_id(params[:emp_id])
  23.  
  24. if @emp_matches == 'False'
  25.  
  26. respond_to do |format|
  27.  
  28. format.json { render json: @user.errors, status: :unprocessable_entity, flash[:error] => "Error No ID found." }
  29. end
  30.  
  31. else
  32.  
  33. @visual = Visual.find_by_id(params[:emp_id])
  34.  
  35. @emp_first_name = @visual.first_name
  36.  
  37. @emp_last_name = @visual.last_name
  38.  
  39.  
  40. render :json => {
  41.  
  42. :emp_first_name => @emp_first_name,
  43. :emp_last_name => @emp_last_name
  44. }
  45. end
  46. end
  47.  
  48. $(document).ready(function(){
  49.  
  50. $('#emp_id').change(function() {
  51. var url = "/user/populate_form?emp_id="+$(this).val();
  52. $.getJSON(url, function(data) {
  53. if(!(data.emp_first_name === undefined))
  54. $('#emp_first_name').val(data.emp_first_name);
  55. if(!(data.last_name === undefined))
  56. $('#emp_last_name').val(data.emp_last_name);
  57. });
  58. }
  59. );
  60. });
  61.  
  62. Table is called Employee
  63. ID
  64. first_name
  65. last_name
  66.  
  67. Table is called User
  68.  
  69.  
  70. emp_id
  71. emp_first_name
  72. emp_last_name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement