我试图把一个简单的链接编辑和删除,但我没有看到路径
rake路线输出:
movie_reviews POST /movies/:movie_id/reviews(.:format) reviews#create
new_movie_review GET /movies/:movie_id/reviews/new(.:format) reviews#new
edit_movie_review GET /movies/:movie_id/reviews/:id/edit(.:format) reviews#edit
movie_review PATCH /movies/:movie_id/reviews/:id(.:format) reviews#update
PUT /movies/:movie_id/reviews/:id(.:format) reviews#update
DELETE /movies/:movie_id/reviews/:id(.:format) reviews#destroy
movies GET /movies(.:format) movies#index
POST /movies(.:format) movies#create
new_movie GET /movies/new(.:format) movies#new
edit_movie GET /movies/:id/edit(.:format) movies#edit
movie GET /movies/:id(.:format) movies#show
PATCH /movies/:id(.:format) movies#update
PUT /movies/:id(.:format) movies#update
DELETE /movies/:id(.:format) movies#destroy
root GET / movies#index
reviews_controller:
def destroy
@review.destroy
respond_to do |format|
format.html { redirect_to movie_path(@movie), notice: 'Review was successfully deleted.' }
format.json { head :no_content }
end
end
movies_controller:
def destroy
@movie.destroy
respond_to do |format|
format.html { redirect_to movies_url, notice: 'Movie was successfully destroyed.' }
format.json { head :no_content }
end
end
修改路径:
<%= link_to 'Edit', edit_movie_review_path(@movie, @review) %>
我很高兴在rails先生,怜悯我,慢慢地请:&#39;(
答案 0 :(得分:1)
它在那里
edit_movie_review GET /movies/:movie_id/reviews/:id/edit(.:format) reviews#edit
edit_movie GET /movies/:id/edit(.:format) movies#edit
movie DELETE /movies/:id(.:format) movies#destroy
movie_review DELETE /movies/:movie_id/reviews/:id(.:format) reviews#destroy
现在,这里是您需要delete
电影和评论的链接。
= link_to 'Delete Movie', movie_path(@movie), method: 'delete'
= link_to 'Delete Review', movie_review_path(@movie, @review), method: 'delete'
与编辑类似,
= link_to 'Edit Movie', edit_movie_path(@movie)
= link_to 'Delete Review', edit_movie_review_path(@movie, @review), method: 'delete'
希望有所帮助!
答案 1 :(得分:0)
Nahhhh我找到了一个答案,我需要通过我想要编辑的id
review
。目前我没有传递它导致错误..问题出在路径
<%= link_to 'Edit', edit_movie_review_path(@movie, @review) %>
更改为:
<%= link_to 'Edit', edit_movie_review_path(@movie, review) %>
看起来相似没有?我只是从上面的@
删除了review
但是......真是个笑话..它已经把我拖了2天......但它值得吗?