所以我有關於電影的這個數據庫。我爲它創建了一個resources :movies
條目進入我的路由文件,這應該爲它提供所需的每個路由。嘗試更新數據庫條目時路由錯誤
這是我的電影控制器:https://github.com/Veske/form/blob/ryhm/app/controllers/movies_controller.rb
這是我的錯誤,當我嘗試在whatever.com/movies/1/edit編輯影片:
Routing Error
No route matches [POST] "/movies/1/edit"
這些都是電影路線現在:
movies_path GET /movies(.:format) movies#index
POST /movies(.:format) movies#create
new_movie_path GET /movies/new(.:format) movies#new
edit_movie_path GET /movies/:id/edit(.:format) movies#edit
movie_path GET /movies/:id(.:format) movies#show
PATCH /movies/:id(.:format) movies#update
PUT /movies/:id(.:format) movies#update
DELETE /movies/:id(.:format) movies#destroy
現在人們清楚地看到,的確有電影沒有POST /:現在ID /編輯。但爲什麼呢?我輸入的路線不應該給我嗎?
編輯:
鏈接到電影查看:https://github.com/Veske/form/blob/ryhm/app/views/movies/edit.html.erb
明白了,試圖現在修復它.. – Veske
好吧我使用PUT:<%= form_for:movie,:html => {:method =>:put} do | f | %> 但是這並沒有改變我沒有爲電影/:id/edit放置路線的事實。我怎樣才能獲得這條路線?我的意思是......資源應該爲我做這件事? – Veske
在您的控制器中,在編輯動作中,在一個實例變量(例如'@movie = Movie.find(params [:id])')中加載電影,然後執行'form_for @ movie' – CDub