0
我相信我有一個路由問題:我有一個功能,允許用戶留下審查一個特定的個人。所以我有一個評論模型和一個個人模型。我試圖找到一種方法來刪除該用戶的具體評論。刪除評論Rails路由
的routes.rb:
resources :individuals do
collection do
get 'search'
end
collection do
get 'schools'
end
member do
post 'flag', :individuals
end
resources :reviews do
member do
post 'flag', 'vote', 'downvote', :review
end
resources :reviews, only: [:index, :create]
end
end
resources :reviews, only: [:destroy, :update, :edit]
所以,我相信,如果我這樣做的權利,我會嵌套的審查指標和創建:individuals/1/reviews/2
但不採取行動摧毀,更新和編輯:reviews/1/edit
。
點評控制器:
def destroy
@review.destroy
respond_to do |format|
format.html { redirect_to @professor, notice: 'Review was successfully destroyed.' }
format.json { head :no_content }
end
end
View.html.rb:
<% if @review.blank? %>
Nothing to review!
<% else %>
<div class="list-group">
<ul class="list-unstyled">
<% @review.each do |review| %>
<li class="list-group-item"> <%= review.comment %> Review Flagged:
<%= pluralize(review.flag, 'time') %>. <%= link_to 'View', professor_review_path(review.professor, review) %>
<%= link_to 'Edit', edit_individual_review_path(review.individual, review) %>
<%= link_to 'Delete', destroy_review_path(review), data: {confirm: "Are you sure you want to delete this review?"} %> </li>
<% end %>
</ul>
</div>
<% end %>
視圖頁面無法正常工作,我得到一個
NoMethodError: undefined method `destroy_review_path' for #<#<Class:0x007fb095e46e28>:0x007fb09d1afdb0>
Did you mean? edit_review_path
我得到這個爲工作刪除個人。
嘿非常感謝你。你真的幫我解決了這個問題,我解決的另一個問題是我有一個before_action設置個人,但我改變了它:'before_action:set_professor,:except => [:flag,:vote,:destroy] '它現在起作用了。 – tfantina
嘿,沒問題,請把這個標記爲答案?另外,使用'before_action,expect:[:action]'我發現有一種危險......不確定你的上下文是什麼,但我總是執行'before_action,只有:[:action]'。 – fbelanger