解決したいこと
編集ページで編集したものを、正しく更新できるように実装したい
なぜがRockTaskに保存されているid 1は更新できるのだが、それ以外は以下のようなエラーが出る
エラー画面
該当するルーティングのコード
(routes.rb)
ruby
1 resources :rock_information do 2 resources :rock_task, only: [:new, :create, :show, :edit, :update] 3 collection do 4 get 'search' 5 end 6 end
rails routesを実行した結果
(rails routesの結果)
root GET / top#index rock_information_rock_task_index POST /rock_information/:rock_information_id/rock_task(.:format) rock_task#create new_rock_information_rock_task GET /rock_information/:rock_information_id/rock_task/new(.:format) rock_task#new edit_rock_information_rock_task GET /rock_information/:rock_information_id/rock_task/:id/edit(.:format) rock_task#edit rock_information_rock_task GET /rock_information/:rock_information_id/rock_task/:id(.:format) rock_task#show PATCH /rock_information/:rock_information_id/rock_task/:id(.:format) rock_task#update PUT /rock_information/:rock_information_id/rock_task/:id(.:format) rock_task#update search_rock_information_index GET /rock_information/search(.:format) rock_information#search rock_information_index GET /rock_information(.:format) rock_information#index POST /rock_information(.:format) rock_information#create new_rock_information GET /rock_information/new(.:format) rock_information#new edit_rock_information GET /rock_information/:id/edit(.:format) rock_information#edit rock_information GET /rock_information/:id(.:format) rock_information#show PATCH /rock_information/:id(.:format) rock_information#update PUT /rock_information/:id(.:format) rock_information#update DELETE /rock_information/:id(.:format) rock_information#destroy search_gym_information_index GET /gym_information/search(.:format) gym_information#search gym_information_index GET /gym_information(.:format) gym_information#index POST /gym_information(.:format) gym_information#create new_gym_information GET /gym_information/new(.:format) gym_information#new edit_gym_information GET /gym_information/:id/edit(.:format) gym_information#edit gym_information GET /gym_information/:id(.:format) gym_information#show PATCH /gym_information/:id(.:format) gym_information#update PUT /gym_information/:id(.:format) gym_information#update
該当すると思うコントローラー
(rock_task_controller)
ruby
1 def edit 2 @task = RockTask.find(params[:rock_information_id]) 3 end 4 5 def update 6 @task = RockTask.find(params[:rock_information_id]) 7 if @task.update(rock_task_params) 8 redirect_to "/rock_information/#{@task.rock_information_id}" 9 else 10 render :edit 11 end 12 end
あなたの回答
tips
プレビュー