以宁静的方式销毁嵌套资源

发布于 2024-08-27 01:33:01 字数 1546 浏览 8 评论 0原文

我正在寻求帮助来销毁 Merb 中的嵌套资源。我当前的方法似乎接近正确,但控制器在销毁嵌套对象期间引发InternalServerError

这里是有关请求的所有详细信息,请不要犹豫询问更多:)

谢谢,

Alex


我正在尝试使用以下路径销毁嵌套资源,其中

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

给出了 jQuery 请求(delete_ 方法是 $. ajax 与“DELETE”):

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

在位置控制器端,我有:

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

和日志:

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)

I'm looking for help destroying a nested resource in Merb. My current method seems near correct, but the controller raise an InternalServerError during the destruction of the nested object.

Here comes all the details concerning the request, don't hesitate to ask for more :)

Thanks,

Alex


I'm trying to destroy a nested resources using the following route in

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

Which gives in jQuery request (delete_ method is a implementation of $.ajax with "DELETE"):

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

In the Location controller side, I've got:

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 log:

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)

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

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

发布评论

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

评论(2

一笑百媚生 2024-09-03 01:33:01

并非所有浏览器实际上都支持发送真正的 DELETE 请求。常见的解决方法是使用带有特殊参数“_method=DELETE”的 POST。

假设您的浏览器实际上正在发送 DELETE 请求,则回溯或错误中的更多信息将有助于进一步调试。

Not all browsers actually support sending a real DELETE request. A common work around is to use a POST with a special param of "_method=DELETE".

Assuming your browser actually is sending the DELETE request, a backtrace or some more information from the error would be helpful for further debugging.

洒一地阳光 2024-09-03 01:33:01

在我看来,正在引发InternalServerError。我认为更好的表达问题的方式是“为什么 @location.destroy 返回 false?”。

在控制台中尝试一下,看看,我猜您在某种 *before_destroy* 回调中失败了,或者可能与实体模型中的另一个规则发生了冲突。

It looks to me like you are raising the InternalServerError. I think a better way to phrase the question would be "why is @location.destroy returning false?".

Try it in the console and see, I'm guessing you are failing some kind of *before_destroy* callback, or perhaps running afoul of another rule in your Entity model.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文