2010-03-30 94 views
4

我在尋找幫助摧毀Merb的一個嵌套的資源。我目前的方法似乎接近正確,但控制器在銷燬嵌套對象期間引發了一個InternalServerError銷燬嵌套資源RESTful方式

這裏談到關於請求的所有細節,不要猶豫,要求更多:)

感謝,

亞歷


我試圖摧毀一個嵌套的資源使用以下路由

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

哪給出了jQuery請求(delete_m ethod是$就以 「刪除」 已實施):

$.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) 

回答

0

並非所有的瀏覽器都支持發送真正的DELETE請求。常見的解決方法是使用帶有「_method = DELETE」特殊參數的POST。

假設你的瀏覽器實際發送刪除請求,回溯或從錯誤一些更多的信息將是進一步的調試很有幫助。

0

它看起來對我像你提高InternalServerError。我認爲更好的方式來解釋這個問題將是「爲什麼@ location.destroy返回false?」。

嘗試在控制檯看看,我猜你是失敗的某種* before_destroy *回調,或者在實體模型相抵觸另一個規則的運行。