【问题标题】:ajax in rails with collection_select带有collection_select的rails中的ajax
【发布时间】:2013-08-23 13:37:55
【问题描述】:

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

在我看来,像这样使用 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)

【问题讨论】:

  • 您能否包含此请求的 Rails 日志?
  • 感谢@RobDiMarco 我现在加入!

标签: ruby-on-rails ruby-on-rails-3.2


【解决方案1】:

在日志中:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-01-15
    • 2013-01-24
    • 2012-11-01
    • 2016-09-10
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多