简体   繁体   English

Rails 6 Route Error未定义的局部变量或方法

[英]Rails 6 Route Error undefined local variable or method

Getting this error with some of my routes.我的一些路线出现此错误。
undefined local variable or method `export_on_demand_dictionary_processor_path' for #ActionView::Base:0x0000000002ada0 Did you mean? #ActionView::Base:0x0000000002ada0 的未定义局部变量或方法 `export_on_demand_dictionary_processor_path' 您是说什么? export_on_demand_dictionary_processor_index_path export_on_demand_dictionary_processor_index_path

How do I fix this error without adding 'index' to all the route paths?如何在不向所有路由路径添加“索引”的情况下修复此错误?

Error happens on the url path. url 路径发生错误。

$.ajax({
      type: 'POST',
      url: "<%= export_on_demand_dictionary_processor_path %>",
      data: $('#export_params_input').val() + '&' + $.param({'build_request_id' : $("#build_request_id").val()}),
      success: function(data, text_status, xhr) {
        window.location.href = data["new_href"];
        $("#load_build_section :input").attr("disabled", false);
        $("#export_progress_message").hide();
      },
      error: function(xhr) {
        $("#load_build_section :input").attr("disabled", true);
        $("#export_progress_message").html("Export failed. (HTTP " + xhr.status + ")");

      }
    })

This is what my route.rb looks like.这就是我的 route.rb 的样子。

resources :dictionary_processor, :as  => :dictionary_processor, :only => [] do
  collection {
    get 'import';
    get 'propose_on_demand';
    post 'run_import';
    get 'propose_build';
    post 'export_on_demand';
}

You can change resources to resource or dictionary_processor to dictionary_processors .您可以将resources更改为resource或将dictionary_processor更改为dictionary_processors Singular and plural in names are important in rails.名称中的单数和复数在 Rails 中很重要。

Just be careful because the controller name will change to plural.请小心,因为控制器名称将变为复数。 Before and after the change, you can check your routes with a command to see what has changed在更改之前和之后,您可以使用命令检查您的路线以查看更改的内容

rails routes

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM