以宁静的方式销毁嵌套资源
我正在寻求帮助来销毁 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
并非所有浏览器实际上都支持发送真正的 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.
在我看来,你正在引发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.