0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Unknown action The action 'show' could not be found for Api::V1::UsersController

Posted at

症状

Railsでアクションを編集して、「http://localhost:3000/api/v1/users/1 」を叩いたたところ、以下エラーが発生しました。 翻訳すると「アクションが見つからない」と言われています。

image.png

ログは以下になります。

UsersController
AbstractController::ActionNotFound (The action 'show' could not be found for Api::V1::UsersController):

actionpack (6.0.3.7) lib/abstract_controller/base.rb:131:in `process'
actionview (6.0.3.7) lib/action_view/rendering.rb:39:in `process'
actionpack (6.0.3.7) lib/action_controller/metal.rb:190:in `dispatch'
actionpack (6.0.3.7) lib/action_controller/metal.rb:254:in `dispatch'
actionpack (6.0.3.7) lib/action_dispatch/routing/route_set.rb:50:in `dispatch'
actionpack (6.0.3.7) lib/action_dispatch/routing/route_set.rb:33:in `serve'
actionpack (6.0.3.7) lib/action_dispatch/journey/router.rb:49:in `block in serve'
actionpack (6.0.3.7) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (6.0.3.7) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (6.0.3.7) lib/action_dispatch/routing/route_set.rb:834:in `call'
warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
warden (1.2.9) lib/warden/manager.rb:34:in `catch'
warden (1.2.9) lib/warden/manager.rb:34:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:27:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
activerecord (6.0.3.7) lib/active_record/migration.rb:567:in `call'
actionpack (6.0.3.7) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (6.0.3.7) lib/active_support/callbacks.rb:101:in `run_callbacks'
actionpack (6.0.3.7) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (6.0.3.7) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.3.7) lib/action_dispatch/middleware/actionable_exceptions.rb:18:in `call'
actionpack (6.0.3.7) lib/action_dispatch/middleware/debug_exceptions.rb:32:in `call'
actionpack (6.0.3.7) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (6.0.3.7) lib/rails/rack/logger.rb:37:in `call_app'
railties (6.0.3.7) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (6.0.3.7) lib/active_support/tagged_logging.rb:80:in `block in tagged'
activesupport (6.0.3.7) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (6.0.3.7) lib/active_support/tagged_logging.rb:80:in `tagged'
railties (6.0.3.7) lib/rails/rack/logger.rb:26:in `call'
actionpack (6.0.3.7) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
actionpack (6.0.3.7) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (6.0.3.7) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (6.0.3.7) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (6.0.3.7) lib/action_dispatch/middleware/static.rb:126:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (6.0.3.7) lib/action_dispatch/middleware/host_authorization.rb:82:in `call'
rack-cors (1.1.1) lib/rack/cors.rb:100:in `call'
railties (6.0.3.7) lib/rails/engine.rb:527:in `call'
puma (4.3.8) lib/puma/configuration.rb:228:in `call'
puma (4.3.8) lib/puma/server.rb:718:in `handle_request'
puma (4.3.8) lib/puma/server.rb:472:in `process_client'
puma (4.3.8) lib/puma/server.rb:328:in `block in run'
puma (4.3.8) lib/puma/thread_pool.rb:134:in `block in spawn_thread'

該当のコントローラーは以下になります。

UsersController
module Api
    module V1 
        class UsersController < ApplicationController
          def sho
            user = User.find_by(id: 1)
            render json: {
                        user: user
                    }, status: :ok
          end
        end
    end
end

解決方法

アクションの「show」の部分が「sho」になっていました。
UsersController
module Api
    module V1 
        class UsersController < ApplicationController
          def show
            user = User.find_by(id: 1)
            render json: {
                        user: user
                    }, status: :ok
          end
        end
    end
end

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?