Updating table using UJS

Hi all,

I have an application in which i am displaying employee details, based
on the onChange event of the employee’s group combobox i need to update
the table contents.Below is the code so far done.

new.html.erb

<%= form_for (@employee) do |f| %>

…(Displaying only necessary code)…

<%= f.label :group_id, "Group" %> <%= f.collection_select(:group_id, Group.order(:name), :id, :name, { :prompt => true }) %>
............................................ ............................................ <% @employees.each do |employee| %>
> <%= employee.group.name %>
............................................ ............................................

employee.js.cofee

jQuery ->
$(’#employee_group_id’).change ->
$(‘div.group’).empty()
$(‘div.name’).empty()
$(‘div.gender’).empty()
$(‘div.experience’).empty()
theVal = $(’#employee_group_id’).val();
theURL = ‘/employeesAjax/’ + theVal;

$.ajax({
   url: theURL
});

employees_controller

def ajaxEmployees
@employee = Employee.find_all_by_group_id(params[:id])
end

ajaxEmployees.js.erb

? No idea what to do here

routes.rb

match ‘employeesAjax/:id’, :to => ‘employees#ajaxEmployees’
resources :employees

Regards,
Abhishek T

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs