Home > other >  Rails 6 Route Error undefined local variable or method
Rails 6 Route Error undefined local variable or method

Time:05-20

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

CodePudding user response:

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
  • Related