带有 collection_select 的 rails 中的 ajax [英] ajax in rails with collection_select

查看:54
本文介绍了带有 collection_select 的 rails 中的 ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我正在尝试根据我在使用 ajax 更改 collection_select 时执行的咨询请求刷新此 div #my_id4.

H everyone I am try to refresh this div #my_id4 with the request of the consult that I execute when change a collection_select with ajax.

我认为像这样的 javascript 选择...

I have in my view the select with javascript like this...

 =collection_select(:department, :id, Department.all, :id, :name, options={:prompt=>"Seleccione departamento"})

这是javascript代码

this is the javascript code

:javascript
  $(document).ready(function(){
  $('#department_id').change(function(){
    $.ajax({
      url:"movements/find_by_department",
      type: "GET",
      data: { valor: $('#department_id').val() }
    });
  });
  })

在我的路由器中,我有这个...

in my router I have this...

resources :movements do
  get 'find_by_department'
end

在我的控制器中我有这个

and in my controller I have this

  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 视图中我有这个.

in the view department_chart.js.erb I have this.

$("#my_id4").html("change!!!")

$("#my_id4").html("change!!!")

但是当我执行应用程序时,我得到了这个..

but when I execute the application I obtain this..

Request URL:http://localhost:3000/movements/find_by_department?valor=5
Request Method:GET
Status Code:302 Found
Request Headersview source

响应为空!就像不执行方法一样.

and the responce in empty! is like don't execute the method.

任何想法!!!

日志是这样的

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)

推荐答案

在日志中:

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

发出请求的用户似乎权限失败,导致重定向.

There looks to be a permission failure for the user making the request that is causing the redirection.

这篇关于带有 collection_select 的 rails 中的 ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆