阿贾克斯与collection_select轨道(ajax in rails with collec

2019-10-29 09:37发布

^ h大家我尝试刷新这个div #my_id4用的要求,请查阅我执行时变化的collection_select阿贾克斯。

我已经在我看来,选择使用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)

Answer 1:

在日志:

Se ha consultado permiso para admin::movements::show
Redirected to http://localhost:3000/movements
Filter chain halted as :permission_check rendered or redirected

有看起来是制作导致该重定向请求的用户权限失效。



文章来源: ajax in rails with collection_select