I have a dropdown in view that is using js I pass the selected item from dropdown to controller, inside the controller I ran a query using the selected item from dropdown to extract some records. Now the problem is that I cannot display the query result to view. Basically I cannot trigger the controller to display in view. Any help greatly appreciated.
Here is the js to pass the data to controller:
<script type="text/JavaScript">
$(function(){
$('.defined_call').bind('change', function(){
alert($(this).val());
$.ajax({
url: "<%= changeowner_path %>",
data: { my_str: $(this).val() }
});
});
});
</script>
<%= select_tag "dropdown_cases", options_for_select(@ownerlist),{:id=>"defined_Id",:class
=> "defined_call'} %>
Here is the controller:
class ReassignsController < ApplicationController
def changeowner
i=0
$myarr=[]
ownerl = Transaction.owner#declaredin model
@ownerlist=ownerl.collect { |c| [ c, c ] }#make it for dropdown
value=params[:my_str]#return value from dropdown
$value1=value.to_s#make it for owner table
@owner_records=Transaction.where(:owner => $value1)
===> I would like to display to the view?
end
end
Here is the view that I am using:
<table class="table table-condensed" id="sortTableExample">
<tr>
<th style="text-align:center">Book Name</th>
<th style="text-align:center">Owner</th>
</tr>
<% @owner_records.each do |arr_data| %>
<tr>
<td style="text-align:center"><%= arr_data.book%></td>
<td style="text-align:center"><%= arr_data.owner%></td>
</tr>
<% end %>
</table>
Joe, Try something like: