0
我有link_to
幫助程序的嵌套刪除方法的問題。Rails 4.2.5 link_to刪除方法
這裏是我的路線:
resources :restaurants, only: [:new, :show, :edit, :index,:create] do
resources :reservations, only: [:new, :show, :edit, :index, :create]
resources :reviews
end
這裏是我的檢討控制器動作:
def destroy
@review = Review.find(params[:id])
@review.destroy
end
和我的user#show
代碼:
<div class="panel-body">
<h1> <%= pluralize(@user.reviews.count ,'review') %> from <%= @user.name %> </h1>
<% @user.reviews.order(created_at: :desc).each do |review| %>
<ul>
<li><em>Review for restaurant: </em><%= review.restaurant.name %></li>
<em>Review comment: </em> <%= review.comment %></br>
<%= link_to 'edit comment', edit_restaurant_review_path(review.restaurant_id, review.id) %>
<%= link_to 'delete comment', restaurant_review_path(@user, review.id) , method: :delete, data:{confirm:"are you sure you want to delete this review"} %>
</ul>
<% end %>
</div>
這裏是我的路線:
restaurant_reviews GET /restaurants/:restaurant_id/reviews(.:format) reviews#index
POST /restaurants/:restaurant_id/reviews(.:format) reviews#create
new_restaurant_review GET /restaurants/:restaurant_id/reviews/new(.:format) reviews#new
edit_restaurant_review GET /restaurants/:restaurant_id/reviews/:id/edit(.:format) reviews#edit
restaurant_review GET /restaurants/:restaurant_id/reviews/:id(.:format) reviews#show
PATCH /restaurants/:restaurant_id/reviews/:id(.:format) reviews#update
PUT /restaurants/:restaurant_id/reviews/:id(.:format) reviews#update
DELETE /restaurants/:restaurant_id/reviews/:id(.:format) reviews#destroy
我似乎無法刪除我的評論。我傳遞了錯誤的變量嗎? 到'restaurant_review_path'?我的路線似乎是對的。因爲我的編輯link_to
幫手正在工作。
@Philip是的,因爲它刪除,然後你不*做任何事*。您需要創建一個視圖來呈現或重定向某處。 – meagar
謝謝,讓它工作。我應該在我的控制器中重定向 – Philip
這應該被接受,如果它的工作。 –