简体   繁体   中英

No Delete and Edit path in rake routes

Im trying to put a simple link to edit and delete, but i dont see the path

rake routes output:

       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

Edit path:

<%= link_to 'Edit', edit_movie_review_path(@movie, @review) %>

im so new in rails sir, have mercy on me, slowly please :'(

Its there

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

Now here are the links to you need to delete the movie and review respectively.

= link_to 'Delete Movie', movie_path(@movie), method: 'delete'
= link_to 'Delete Review', movie_review_path(@movie, @review), method: 'delete'

Similarly to edit,

= link_to 'Edit Movie', edit_movie_path(@movie)
= link_to 'Delete Review', edit_movie_review_path(@movie, @review), method: 'delete'

Hope that helps!

Nahhhh i found an answer which i need to pass the id of review which i would like to be edited. Currently i'm not passing it which is causing the error.. the problem is in the path

<%= link_to 'Edit', edit_movie_review_path(@movie, @review) %>

change to:

<%= link_to 'Edit', edit_movie_review_path(@movie, review) %>

look similar no? i just remove the @ from the review above though.. what a joke.. its dragging me for 2 days already.. but its worth it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM