Ruby on Rails Sunday, January 27, 2013

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)...
<div class="employeegroup">
<%= f.label :group_id, "Group" %>
<%= f.collection_select(:group_id, Group.order(:name), :id, :name, {
:prompt => true }) %>
</div>
............................................
............................................
<% @employees.each do |employee| %>

<div class="group" title=<%= employee.group.name %>>
<%= employee.group.name %>
</div>
............................................
............................................

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

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment