ruby
1 2class Api::UsersController < ApplicationController 3 4 def update 5 user = User.find(params[:id]) 6 if user.update(user_params) 7 Hint.find(params[:id]).destroy 8 SecretHint.find(params[:id]).destroy 9 render json: @user 10 else 11 @msg = '失敗' 12 render json: @msg 13 end 14 end 15end
updateされると同時にdestroyも動かしたいですがNameError (undefined local variable or method `user_params' for #Api::UsersController:0x007fc1e520f5e0):
このエラーが出ます。
このようなアルゴリズムは可能でしょうか?
また解決策をご教授願います。
※createを使うとROLLBACKになり
ArgumentError (wrong number of arguments (given 0, expected 1..2)):
このエラーが出ました。
Started PATCH "/api/users/2" for 127.0.0.1 at 2018-06-02 22:21:36 +0900 Processing by Api::UsersController#update as JSON Parameters: {"{\n \"like_person_twitter_id\" "=>" \"3\"\n}", "id"=>"2"} User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 LIMIT 1 ↳ app/controllers/api/users_controller.rb:8 Completed 400 Bad Request in 22ms (ActiveRecord: 0.7ms) ActionController::ParameterMissing (param is missing or the value is empty: user): app/controllers/api/users_controller.rb:27:in `user_params' app/controllers/api/users_controller.rb:9:in `update'
追記/今は上のようなエラーが出ています。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。