Destruction of invested resources in a calm way

I am looking for help in destroying a nested resource in Merb. My current method seems almost correct, but the controller raises an InternalServerError while destroying a nested object.

Here are all the details regarding the request, feel free to ask more :)

Thanks,

Alex


I am trying to destroy nested resources using the following route in

router.resources :events, Orga::Events do |event| event.resources :locations, Orga::Locations end 

What gives jQuery in the query (the delete_ method is an implementation of $ .ajax with "DELETE"):

 $.delete_("/events/123/locations/456"); 

On the side of the location controller, I have:

 def delete(id) @location = Location.get(id) raise NotFound unless @location if @location.destroy redirect url(:orga_locations) else raise InternalServerError end end 

And the magazine:

 merb : worker (port 4000) ~ Routed to: {"format"=>nil, "event_id"=>"123", "action"=>"destroy", "id"=>"456", "controller"=>"letsmotiv/locations"} merb : worker (port 4000) ~ Params: {"format"=>nil, "event_id"=>"123", "action"=>"destroy", "id"=>"456", "controller"=>"letsmotiv/locations"} ~ (0.000025) SELECT `id`, `class_type`, `name`, `prefix`, `type`, `capacity`, `handicap`, `export_name` FROM `entities` WHERE (`class_type` IN ('Location') AND `id` = 456) ORDER BY `id` LIMIT 1 ~ (0.000014) SELECT `id`, `streetname`, `phone`, `lat`, `lng`, `country_region_city_id`, `location_id`, `organisation_id` FROM `country_region_city_addresses` WHERE `location_id` = 456 ORDER BY `id` LIMIT 1 merb : worker (port 4000) ~ Merb::ControllerExceptions::InternalServerError - (Merb::ControllerExceptions::InternalServerError) 
+4
source share
2 answers

Not all browsers actually support sending a real DELETE request. A common goal is to use POST with the special parameter "_method = DELETE".

Assuming your browser is actually sending a DELETE request, backtracking or additional error information will be useful for further debugging.

0
source

It seems to me that you are raising an InternalServerError. I think the best way to formulate the question is: “Why @ location.destroy returns false?”.

Try it in the console and see, I assume that you are not doing any * callback * before_destroy * or maybe you are executing another rule in your Entity model.

0
source

Source: https://habr.com/ru/post/1305520/


All Articles