How to return the correct location for route with singular resources?

0

When using the controller name in the singular, the route is prefixed with _index to the end of the route name (eg dispute_conference_index ). Within the controller in method create the parameter location in render receives the URL of the registry.

Unfortunately the name passed to location is dispute_conference_url instead of dispute_conference_index .

See below the route setting I'm using:

resources :disputes, shallow: true do
  scope module: :dispute do
    resources :conference, except: :index
  end
end

See the details of routes:

                 Prefix Verb    URI Pattern                                Controller#Action
conferences              GET    /conferences(.:format)                     conferences#index {:format=>:json}
dispute_conference_index POST   /disputes/:dispute_id/conference(.:format) dispute/conference#create {:format=>:json}
conference               GET    /conference/:id(.:format)                  dispute/conference#show {:format=>:json}
                         PATCH  /conference/:id(.:format)                  dispute/conference#update {:format=>:json}
                         PUT    /conference/:id(.:format)                  dispute/conference#update {:format=>:json}
                         DELETE /conference/:id(.:format)                  dispute/conference#destroy {:format=>:json}
                         PUT    /conference/:id/start(.:format)            dispute/conference#start {:format=>:json}
                         PUT    /conference/:id/cancel(.:format)           dispute/conference#cancel {:format=>:json}
                         PUT    /conference/:id/finish(.:format)           dispute/conference#finish {:format=>:json}

What is the correct way to fix this question, passing location correct?

Correcting the question : The reason for the error is because of the shallow: true parameter, it changes the path of the routes, causing a manual intervention or through a function (url_path ).

When trying to run the create method, an error will be obtained because location can not be found.

    
asked by anonymous 02.01.2017 / 17:15

1 answer

0

After several attempts and errors, the solution seemed to work. You must first move shallow: true to the resources call, and finally the shallow_prefix: :dispute attribute must be added. See below how it is:

resources :disputes do
  scope module: :dispute, except: :index do
    resources :conference, shallow: true, shallow_prefix: :dispute
  end
end

Done this routes will be mounted as desired:

Prefix Verb         URI Pattern Controller#Action
conferences              GET    /conferences(.:format)                     conferences#index {:format=>:json}
dispute_conference_index POST   /disputes/:dispute_id/conference(.:format) dispute/conference#create {:format=>:json}
dispute_conference       GET    /conference/:id(.:format)                  dispute/conference#show {:format=>:json}
                         PATCH  /conference/:id(.:format)                  dispute/conference#update {:format=>:json}
                         PUT    /conference/:id(.:format)                  dispute/conference#update {:format=>:json}
                         DELETE /conference/:id(.:format)                  dispute/conference#destroy {:format=>:json}
                         PUT    /conference/:id/start(.:format)            dispute/conference#start {:format=>:json}
                         PUT    /conference/:id/cancel(.:format)           dispute/conference#cancel {:format=>:json}
                         PUT    /conference/:id/finish(.:format)           dispute/conference#finish {:format=>:json}

Notice that my controller is mounted on the module dispute this is also related to the problem.

    
02.01.2017 / 18:01