Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Visual < ActiveRecord::Base
- establish_connection :vtest
- self.table_name = 'employee'
- Visual.inheritance_column = 'inheritance_type'
- belongs_to :user
- def emp_matches(x)
- (x.id.to_i == self.id.to_i ? true : false)
- end
- end
- class UserController < ApplicationController
- def populate_form
- @visual = Visual.find_by_id(params[:emp_id])
- if @emp_matches == 'False'
- respond_to do |format|
- format.json { render json: @user.errors, status: :unprocessable_entity, flash[:error] => "Error No ID found." }
- end
- else
- @visual = Visual.find_by_id(params[:emp_id])
- @emp_first_name = @visual.first_name
- @emp_last_name = @visual.last_name
- render :json => {
- :emp_first_name => @emp_first_name,
- :emp_last_name => @emp_last_name
- }
- end
- end
- $(document).ready(function(){
- $('#emp_id').change(function() {
- var url = "/user/populate_form?emp_id="+$(this).val();
- $.getJSON(url, function(data) {
- if(!(data.emp_first_name === undefined))
- $('#emp_first_name').val(data.emp_first_name);
- if(!(data.last_name === undefined))
- $('#emp_last_name').val(data.emp_last_name);
- });
- }
- );
- });
- Table is called Employee
- ID
- first_name
- last_name
- Table is called User
- emp_id
- emp_first_name
- emp_last_name
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement