铁轨6路线错误未定义的本地变量或方法

发布于 2025-01-30 04:12:42 字数 1161 浏览 4 评论 0原文

通过我的一些路线获取此错误。
未定义的本地变量或方法`export_on_demand_dictionary_processor_path'for #actionView :: base:0x0000000002ADA00 你的意思? export_on_demand_dictionary_processor_index_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 + ")");

      }
    })

这就是我的路线。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';
}

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? 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.

$.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.

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';
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无言温柔 2025-02-06 04:12:42

您可以将资源更改为资源dictionary_processor dictionary_processors。名称的单数和复数在铁轨中很重要。

请小心,因为控制器名称将变为复数。
更改之前和之后,您可以使用命令检查路线以查看已更改的内容

rails routes

You can change resources to resource or dictionary_processor to dictionary_processors. Singular and plural in names are important in 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文