当我更改选择时,我在更新 div 时遇到了一些问题。
首先,我在这样的视图中创建我的选择。
=collection_select(:department, :id, Department.all, :id, :name, options={:prompt=>"Seleccione departamento"})
现在我创建一个 ajax 调用来获取 select 的值并找到所有要匹配的日期
:javascript
$(document).ready(function(){
$('#department_id').change(function(){
$.ajax({
url:"/movements/find_by_department",
type: "GET",
data: {valor: $('#department_id').val()}
});
});
})
下一步是创建一个方法“find_by_department”来获取值..并显示一些东西
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
现在是我的问题,我有一个部分的“department_chart”
$("#my_id4").html("@ideas_department")
但 id="my_id4" 不会改变
另一方面,我在控制台中看到了这个
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
我不知道为什么要调用 show 方法
我的路由器里有这个
get 'movements/find_by_department', :as => 'find_by_department'