我有一个窗体模型有一个嵌套的资源(一个图像上传与Carrierwave),并在嵌套的资源我有一个link_to,允许删除图像。点击链接将删除载波项目并删除图像。这一切都完全适用的编辑功能,而是试图去新的屏幕,我收到以下错误时:“没有路线匹配”的错误,但只有在新的
No route matches {:controller=>"listings", :action=>"remove_image"}
(ActionView::Template::Error)
这里是有问题的链接:
<%= link_to "Delete this image", remove_image_path(builder.object.id),
:confirm => "Are you sure you want to delete this image?",
:method => :delete %>
这里是我的路线进入:
match "/remove_image/:id" => "listings#remove_image", :as => "remove_image"
下面是从ListingsController方法:
def remove_image
@image = SecondaryImage.find(params[:id])
@listing = Listing.find(@image.listing_id)
@image.remove_image
@image.destroy
respond_to do |format|
format.html { redirect_to edit_listing_path(@listing),
notice: "Successfully deleted secondary image" }
end
end
UPDATE:耙路线 按照要求,在这里是如何简单地做这涉及到ListingsController
listing_secondary_images GET /listings/:listing_id/secondary_images(.:format) {:action=>"index", :controller=>"secondary_images"}
POST /listings/:listing_id/secondary_images(.:format) {:action=>"create", :controller=>"secondary_images"}
new_listing_secondary_image GET /listings/:listing_id/secondary_images/new(.:format) {:action=>"new", :controller=>"secondary_images"}
edit_listing_secondary_image GET /listings/:listing_id/secondary_images/:id/edit(.:format) {:action=>"edit", :controller=>"secondary_images"}
listing_secondary_image GET /listings/:listing_id/secondary_images/:id(.:format) {:action=>"show", :controller=>"secondary_images"}
PUT /listings/:listing_id/secondary_images/:id(.:format) {:action=>"update", :controller=>"secondary_images"}
DELETE /listings/:listing_id/secondary_images/:id(.:format) {:action=>"destroy", :controller=>"secondary_images"}
listings GET /listings(.:format) {:action=>"index", :controller=>"listings"}
POST /listings(.:format) {:action=>"create", :controller=>"listings"}
new_listing GET /listings/new(.:format) {:action=>"new", :controller=>"listings"}
edit_listing GET /listings/:id/edit(.:format) {:action=>"edit", :controller=>"listings"}
listing GET /listings/:id(.:format) {:action=>"show", :controller=>"listings"}
PUT /listings/:id(.:format) {:action=>"update", :controller=>"listings"}
DELETE /listings/:id(.:format) {:action=>"destroy", :controller=>"listings"}
features GET /features(.:format) {:action=>"index", :controller=>"features"}
POST /features(.:format) {:action=>"create", :controller=>"features"}
new_feature GET /features/new(.:format) {:action=>"new", :controller=>"features"}
edit_feature GET /features/:id/edit(.:format) {:action=>"edit", :controller=>"features"}
feature GET /features/:id(.:format) {:action=>"show", :controller=>"features"}
PUT /features/:id(.:format) {:action=>"update", :controller=>"features"}
DELETE /features/:id(.:format) {:action=>"destroy", :controller=>"features"}
orders GET /orders(.:format) {:action=>"index", :controller=>"orders"}
POST /orders(.:format) {:action=>"create", :controller=>"orders"}
new_order GET /orders/new(.:format) {:action=>"new", :controller=>"orders"}
edit_order GET /orders/:id/edit(.:format) {:action=>"edit", :controller=>"orders"}
order GET /orders/:id(.:format) {:action=>"show", :controller=>"orders"}
PUT /orders/:id(.:format) {:action=>"update", :controller=>"orders"}
DELETE /orders/:id(.:format) {:action=>"destroy", :controller=>"orders"}
preview_listing GET /preview/:id(.:format) {:controller=>"listings", :action=>"preview"}
approve_listing /approve/:id(.:format) {:controller=>"listings", :action=>"approve"}
remove_image /remove_image/:id(.:format) {:controller=>"listings", :action=>"remove_image"}
你可以发布一个耙:路线吗? – David
我更新了我的路线。感谢您看看 – Tonys