Jquery 轨道中的故障级联

Jquery 轨道中的故障级联,jquery,ruby-on-rails,ajax,ruby-on-rails-4,Jquery,Ruby On Rails,Ajax,Ruby On Rails 4,我正在尝试在Rails中设置一个级联选择框。我举一个例子。由于某种原因,我不能使它正常工作。当我在下拉列表中进行新选择时,WEBrick显示ActiveRecord的404 Not Found错误 确切的错误是: Started GET "/estimates/update_areas?product_type_id=1&_=1446822835903" for 50.17.182.190 at 2015-11-06 16:05:23 +0000 Cannot render consol

我正在尝试在Rails中设置一个级联选择框。我举一个例子。由于某种原因,我不能使它正常工作。当我在下拉列表中进行新选择时,WEBrick显示ActiveRecord的404 Not Found错误

确切的错误是:

Started GET "/estimates/update_areas?product_type_id=1&_=1446822835903" for 50.17.182.190 at 2015-11-06 16:05:23 +0000
Cannot render console from 50.17.182.190! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by EstimatesController#show as JS
  Parameters: {"product_type_id"=>"1", "_"=>"1446822835903", "id"=>"update_areas"}
  User Load (0.3ms)  SELECT  "users".* FROM "users" WHERE "users"."id" = $1  ORDER BY "users"."name" ASC LIMIT 1  [["id", 1]]
  Estimate Load (0.3ms)  SELECT  "estimates".* FROM "estimates" WHERE "estimates"."id" = $1  ORDER BY "estimates"."updated_at" DESC LIMIT 1  [["id", 0]]
Completed 404 Not Found in 4ms (ActiveRecord: 0.6ms)


ActiveRecord::RecordNotFound (Couldn't find Estimate with 'id'=update_areas):
  app/controllers/estimates_controller.rb:9:in `show'
出于某种原因,请求被路由到控制器中的“show”方法,我不知道为什么

my estimates_controller.rb中的update_areas方法:

  def update_areas
    @areas = Area.where("product_type_id = ?", params[:product_type_id])
    respond_to do |format|
      format.js
    end
  end
有关路线包括:

  resources :estimates
  get 'estimates/new/update_areas', to: 'estimates#update_areas'
我的咖啡

$ ->
  $(document).on 'change', '#product_type_select', (evt) ->
    $.ajax 'update_areas',
      type: 'GET'
      dataType: 'script'
      data: {
        product_type_id: $("#product_type_select option:selected").val()
      }
      error: (jqXHR, textStatus, errorThrown) ->
        console.log("AJAX Error: #{textStatus}")
      success: (data, textStatus, jqXHR) ->
        console.log("Dynamic area select OK!")
$("#areas_select").empty().append("<%= escape_javascript(render(:partial => @areas)) %>")
和我的更新_areas.js.coffee

$ ->
  $(document).on 'change', '#product_type_select', (evt) ->
    $.ajax 'update_areas',
      type: 'GET'
      dataType: 'script'
      data: {
        product_type_id: $("#product_type_select option:selected").val()
      }
      error: (jqXHR, textStatus, errorThrown) ->
        console.log("AJAX Error: #{textStatus}")
      success: (data, textStatus, jqXHR) ->
        console.log("Dynamic area select OK!")
$("#areas_select").empty().append("<%= escape_javascript(render(:partial => @areas)) %>")
在韦布里克。没有我得到的资源

Parameters: {"product_type_id"=>"2", "_"=>"1447260557305"

这正是我所期望的。为什么,当我在routes文件中添加资源行时,突然传递了一个ID参数

好吧,我终于让它起作用了

在my routes.rb中,估算资源变成:

  resources :estimates do
    get 'update_areas', on: :new
  end
而我的estimates.js.coffee变成了:

$ ->
  $(document).on 'change', '#product_type_select', (evt) ->
    $.ajax
      url:'/estimates/new/update_areas',
      type: 'GET',
      dataType: 'script',
      data: {
        product_type_id: $("#product_type_select option:selected").val()
      }
      error: (jqXHR, textStatus, errorThrown) ->
        console.log("AJAX Error: #{textStatus} #{errorThrown}")
      success: (data, textStatus, jqXHR) ->
        console.log("Dynamic area select OK!")
这接受了适当的参数并更新了目标选择框。希望有一天这能帮助别人