私はActiveRecordのUserControllerにdestroyメソッドを持っています。ActiveRecordは、ユーザーが破棄された後にデータベース内のユーザーを確認しています。その結果404
class Api::V1::UsersController < ApplicationController
skip_before_action :authorized, only: [:create, :destroy]
def create
@user = User.new(user_params)
if @user.save
token = issue_token({ user_id: @user.id})
render json: { user: @user, jwt: token}, status: 201
else
render json: {message: "Username is already taken" }, status: 400
end
end
def show
@user = User.find(params[:id])
render json: {user: @user}, status: 201
end
def update
@user = User.find(params[:id])
if @user == current_user
@user.update_attributes(user_params)
render json: {user: @user}, status: 201
else
render json: {message: "Unable to update"}, status: 400
end
end
def destroy
@user = User.find(params[:id])
if @user == current_user
@user.destroy
render json: {message: "Your account was deleted"}, status: 200
else
render json: {message: "You cannot delete this account"}, status: 400
end
end
private
def user_params
params.permit(:username, :password, :image_uri, :description, :email, links: [])
end
end
私はレールのAPIへの削除要求を送信するために行くたびにActiveRecordのは、レコードが、その後最後に、それは再びユーザーを探しているを削除しません。
Started DELETE "/api/v1/users/8" for 127.0.0.1 at 2017-12-30 15:18:32 -0500
Processing by Api::V1::UsersController#destroy as JSON
Parameters: {"username"=>"pam", "password"=>"[FILTERED]", "email"=>"pam", "id"=>"8", "user"=>{"username"=>"pam", "email"=>"pam"}}
User Load (1.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
User Load (1.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
(1.4ms) BEGIN
UserFollower Load (1.4ms) SELECT "user_followers".* FROM
"user_followers" WHERE "user_followers"."follower_id" = $1 [["follower_id", 8]]
Story Load (1.6ms) SELECT "stories".* FROM "stories" WHERE "stories"."user_id" = $1 [["user_id", 8]]
SQL (1.7ms) DELETE FROM "users" WHERE "users"."id" = $1 [["id", 8]]
(2.2ms) COMMIT
User Load (1.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 8], ["LIMIT", 1]]
Completed 404 Not Found in 414ms (ActiveRecord: 12.3ms)
アクティブなレコードの関連付けと関係があると思いましたか?
class User < ApplicationRecord
validates_presence_of [:username, :email, :password_digest]
has_secure_password
has_many :user_followers, class_name: "UserFollower", foreign_key: "follower_id", dependent: :destroy
has_many :followers, through: :user_followers
has_many :stories, dependent: :destroy
end
これは、スタックトレースです:
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/core.rb:189:in `find'
/Users/Josh/dev/mediumrare-rails/app/controllers/application_controller.rb:27:in `current_user'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/active_model_serializers-0.10.6/lib/action_controller/serialization.rb:30:in `serialization_sco
pe'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/active_model_serializers-0.10.6/lib/action_controller/serialization.rb:43:in `block in get_seri
alizer'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/active_model_serializers-0.10.6/lib/action_controller/serialization.rb:43:in `fetch'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/active_model_serializers-0.10.6/lib/action_controller/serialization.rb:43:in `get_serializer'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/active_model_serializers-0.10.6/lib/action_controller/serialization.rb:61:in `block (2 levels)
in <module:Serialization>'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/renderers.rb:149:in `block in _render_to_body_with
_renderer'
/Users/Josh/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/set.rb:306:in `each_key'
/Users/Josh/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/set.rb:306:in `each'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/renderers.rb:145:in `_render_to_body_with_renderer
'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/renderers.rb:141:in `render_to_body'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/abstract_controller/rendering.rb:24:in `render'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/rendering.rb:36:in `render'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/instrumentation.rb:44:in `block (2 levels) in rend
er'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/core_ext/benchmark.rb:12:in `block in ms'
/Users/Josh/.rvm/rubies/ruby-2.3.4/lib/ruby/2.3.0/benchmark.rb:308:in `realtime'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/core_ext/benchmark.rb:12:in `ms'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/instrumentation.rb:44:in `block in render'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/instrumentation.rb:87:in `cleanup_view_runtime'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/railties/controller_runtime.rb:29:in `cleanup_view_runtime
'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/instrumentation.rb:43:in `render'
/Users/Josh/dev/mediumrare-rails/app/controllers/api/v1/users_controller.rb:34:in `destroy'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/basic_implicit_render.rb:4:in `send_action'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/abstract_controller/base.rb:186:in `process_action'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/rendering.rb:30:in `process_action'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/abstract_controller/callbacks.rb:20:in `block in process_action'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:131:in `run_callbacks'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/abstract_controller/callbacks.rb:19:in `process_action'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/rescue.rb:20:in `process_action'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/instrumentation.rb:32:in `block in process_action'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/notifications.rb:166:in `block in instrument'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/notifications/instrumenter.rb:21:in `instrument'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/notifications.rb:166:in `instrument'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/instrumentation.rb:30:in `process_action'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal/params_wrapper.rb:252:in `process_action'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/railties/controller_runtime.rb:22:in `process_action'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/abstract_controller/base.rb:124:in `process'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal.rb:189:in `dispatch'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_controller/metal.rb:253:in `dispatch'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:31:in `serve'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:50:in `block in serve'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:33:in `each'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/journey/router.rb:33:in `serve'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/routing/route_set.rb:834:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/etag.rb:25:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/conditional_get.rb:38:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/head.rb:12:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activerecord-5.1.4/lib/active_record/migration.rb:556:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/middleware/callbacks.rb:26:in `block in call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/callbacks.rb:97:in `run_callbacks'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/middleware/callbacks.rb:24:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/middleware/executor.rb:12:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/middleware/debug_exceptions.rb:59:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/railties-5.1.4/lib/rails/rack/logger.rb:36:in `call_app'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/railties-5.1.4/lib/rails/rack/logger.rb:24:in `block in call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/tagged_logging.rb:69:in `block in tagged'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/tagged_logging.rb:26:in `tagged'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/tagged_logging.rb:69:in `tagged'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/railties-5.1.4/lib/rails/rack/logger.rb:24:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/middleware/request_id.rb:25:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/runtime.rb:22:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/activesupport-5.1.4/lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/middleware/executor.rb:12:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/actionpack-5.1.4/lib/action_dispatch/middleware/static.rb:125:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/rack-2.0.3/lib/rack/sendfile.rb:111:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/rack-cors-1.0.2/lib/rack/cors.rb:97:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/railties-5.1.4/lib/rails/engine.rb:522:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/puma-3.11.0/lib/puma/configuration.rb:225:in `call'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/puma-3.11.0/lib/puma/server.rb:624:in `handle_request'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/puma-3.11.0/lib/puma/server.rb:438:in `process_client'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/puma-3.11.0/lib/puma/server.rb:302:in `block in run'
/Users/Josh/.rvm/gems/ruby-2.3.4/gems/puma-3.11.0/lib/puma/thread_pool.rb:120:in `block in spawn_thread'
*お使いのコントローラを確認すると役立つことがあります。 – jvillian
見つからないエラーのスタックトレースを見て、それが何を引き起こしているかを教えてくれるのは本当に役に立ちます。 –
現在のユーザーにアカウントを破棄させるようです。ユーザーが削除された後に何をしていても、現在のユーザーをもう一度(現在は存在しない)設定しようとしている可能性がありますか? – inveterateliterate