change a div with ajax when change a select
I have some problem to update a div when I change a select.
First I create my select in a view like this.
=collection_select(:department, :id, Department.all, :id, :name,
options={:prompt=>"Seleccione departamento"})
now I create a ajax call to take the value of the select and find all the
date to match
:javascript
$(document).ready(function(){
$('#department_id').change(function(){
$.ajax({
url:"/movements/find_by_department",
type: "GET",
data: {valor: $('#department_id').val()}
});
});
})
the next step was create a method "find_by_department" to take the value
.. and show something
def find_by_department
id_department = (params[:valor])
@ideas_department = Idea.find_by_department_id(id_department)
respond_to do |format|
format.js {render :department_chart}
end
end
Now is my problem, I have a partial "department_chart" with this
$("#my_id4").html("@ideas_department")
but the id="my_id4" don't change
by the other hands, I see this in console
Started GET "/movements/find_by_department?valor=5" for 127.0.0.1 at
2013-08-22 09:50:04 +0100
Processing by MovementsController#show as */*
Parameters: {"valor"=>"5", "id"=>"find_by_department"}
User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 10
LIMIT 1
Option Load (0.2ms) SELECT "options".* FROM "options" WHERE
"options"."name" = 'ideas_status_updated_date' LIMIT 1
I don´t no why call the show method
I have this in my router
get 'movements/find_by_department', :as => 'find_by_department'
No comments:
Post a Comment