Я реализую в своем первом проекте грубую операцию «удалить», но система воспринимает команду как «get», без ошибок.
это контроллер:
class MoviesController < ApplicationController
def index
@movies = Movie.all
end
#GET /movies/:id
def show
id = params[:id]
@movie = Movie.find(id)
#render plain: 'show'+params[:id]
end
#POST /movies/
# skip_before_action :verify_autenticity_token:
def create
@movie = Movie.create!(params[:movie].permit(:title, :rating, :description, :realease_date))
flash[:notice] = "#{@movie.title} was successfully created."
redirect_to movies_path
end
#new
def new
end
def edit
id = params[:id]
@movie = Movie.find(id)
end
def update
id = params[:id]
@movie = Movie.find(id)
if @movie.update_attributes!(params[:movie].permit(:title,:rating,:realease_date))
flash[:notice] = "#{@movie.title} has been edited."
redirect_to movies_path
end
end
def destroy
id = params[:id]
@movie = Movie.find(id)
@movie.destroy
flash[:notice] = "#{@movie.title} has been deleted."
redirect_to movies_path
end
end
это вид, где можно вызвать операцию «Удалить»:
%h2 Details about #{@movie.title}
%ul#details
%li
Rating:
= @movie.rating
%li
Released on:
= @movie.realease_date#.strftime("%B %d, %Y")
%h3 Description:
%p#description= @movie.description
%h4 Reviews:
- if @movie.reviews.empty?
%p
No reviews for this movie...
-else
- @movie.reviews.each do |r|
- u = Moviegoer.find(r.moviegoer_id)
<b>#{r.vote}</b> (<i>#{Moviegoer.find(r.moviegoer_id).name}</i>) #{r.message} <br />
= link_to 'Add review', new_movie_review_path(@movie)
<br/><br/>
#{link_to 'Edit info', edit_movie_path(@movie)} - #{link_to 'Delete', movie_path(@movie), :method => :delete} - #{link_to 'Back to movie list', movies_path}
Проблема, вероятно, в последней строке, потому что в командной строке сервера «Удалить» не вызывает.
это ответ сервера (последний GET, который выполняется, когда я нажимаю «Удалить» в браузере):
введите описание изображения здесь
файл route.rb:
Rails.application.routes.draw do
resources :movies do
resources :reviews, only: [:new, :create, :destroy]
end
resources :moviegoers
root :to => redirect('/movies')
end
Результат команды "rake маршруты":
Prefix Verb URI Pattern Controller#Action
movie_reviews POST /movies/:movie_id/reviews(.:format) reviews#create
new_movie_review GET /movies/:movie_id/reviews/new(.:format) reviews#new
movie_review 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
moviegoers GET /moviegoers(.:format) moviegoers#index
POST /moviegoers(.:format) moviegoers#create
new_moviegoer GET /moviegoers/new(.:format) moviegoers#new
edit_moviegoer GET /moviegoers/:id/edit(.:format) moviegoers#edit
moviegoer GET /moviegoers/:id(.:format) moviegoers#show
PATCH /moviegoers/:id(.:format) moviegoers#update
PUT /moviegoers/:id(.:format) moviegoers#update
DELETE /moviegoers/:id(.:format) moviegoers#destroy
root GET / redirect(301, /movies)
rails_service_blob GET /rails/active_storage/blobs/:signed_id /*filename(.:format) active_storage/blobs#show
rails_blob_representation GET /rails/active_storage/representations/:signed_blob_id/:variation_key/*filename(.:format) active_storage/representations#show
rails_disk_service GET /rails/active_storage/disk/:encoded_key/*filename(.:format) active_storage/disk#show
update_rails_disk_service PUT /rails/active_storage/disk/:encoded_token(.:format) active_storage/disk#update
rails_direct_uploads POST /rails/active_storage /direct_uploads(.:format) active_storage/direct_uploads#create