大家好,我正在尝试#my_id4
使用我在使用 ajax 更改 collection_select 时执行的咨询请求来刷新此 div。
在我看来,我有这样的 javascript 选择...
=collection_select(:department, :id, Department.all, :id, :name, options={:prompt=>"Seleccione departamento"})
这是javascript代码
:javascript
$(document).ready(function(){
$('#department_id').change(function(){
$.ajax({
url:"movements/find_by_department",
type: "GET",
data: { valor: $('#department_id').val() }
});
});
})
在我的路由器中,我有这个...
resources :movements do
get 'find_by_department'
end
在我的控制器中我有这个
def find_by_department
@ideas_department = Idea.find_by_department_id(params[:valor])
respond_to do |format|
format.js {render :action => :department_chart}
end
end
在视图 department_chart.js.erb 我有这个。
$("#my_id4").html("改变!!!")
但是当我执行应用程序时,我得到了这个..
Request URL:http://localhost:3000/movements/find_by_department?valor=5
Request Method:GET
Status Code:302 Found
Request Headersview source
和空的响应!就像不执行该方法。
任何想法!!!
日志是这样的
Started GET "/movements/find_by_department?valor=6" for 127.0.0.1 at 2013-08-23 14:46:28 +0100
Processing by MovementsController#show as */*
Parameters: {"valor"=>"6", "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
Se ha consultado permiso para admin::movements::show
Redirected to http://localhost:3000/movements
Filter chain halted as :permission_check rendered or redirected
Completed 302 Found in 4ms (ActiveRecord: 0.5ms)
Started GET "/movements" for 127.0.0.1 at 2013-08-23 14:46:28 +0100
Processing by MovementsController#index as */*
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
Se ha consultado permiso para admin::movements::index
Company Load (0.2ms) SELECT "companies".* FROM "companies" WHERE "companies"."id" = 4 LIMIT 1
Movement Load (0.5ms) SELECT "movements".* FROM "movements" INNER JOIN "ideas" ON "movements"."idea_id" = "ideas"."id" INNER JOIN "departments" ON "ideas"."department_id" = "departments"."id" WHERE "departments"."company_id" = 4
Department Load (0.3ms) SELECT "departments".* FROM "departments"
Rendered movements/index.html.haml within layouts/logged (5.2ms)