【Rails】NoMethodError (undefined method `empty?' for true:TrueClass)と言われた件【device_token_auth】

<h2>症状</h2>
device_token_authでsign_upをしようとしたときに、以下エラーが発生しました。
翻訳すると、「メソッドがないよ」でした。メソッドを上手く認識出てきていないようです。

```terminal:error
Completed 500 Internal Server Error in 5ms (ActiveRecord: 0.0ms | Allocations: 705)

NoMethodError (undefined method `empty?' for true:TrueClass):

devise_token_auth (1.1.5) app/controllers/devise_token_auth/registrations_controller.rb:198:in `validate_post_data'
devise_token_auth (1.1.5) app/controllers/devise_token_auth/registrations_controller.rb:190:in `validate_sign_up_params'
activesupport (6.0.3.7) lib/active_support/callbacks.rb:428:in `block in make_lambda'
activesupport (6.0.3.7) lib/active_support/callbacks.rb:181:in `block (2 levels) in halting_and_conditional'
actionpack (6.0.3.7) lib/abstract_controller/callbacks.rb:34:in `block (2 levels) in <module:Callbacks>'
activesupport (6.0.3.7) lib/active_support/callbacks.rb:182:in `block in halting_and_conditional'
activesupport (6.0.3.7) lib/active_support/callbacks.rb:513:in `block in invoke_before'
activesupport (6.0.3.7) lib/active_support/callbacks.rb:513:in `each'
activesupport (6.0.3.7) lib/active_support/callbacks.rb:513:in `invoke_before'
activesupport (6.0.3.7) lib/active_support/callbacks.rb:134:in `run_callbacks'
actionpack (6.0.3.7) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (6.0.3.7) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (6.0.3.7) lib/action_controller/metal/instrumentation.rb:33:in `block in process_action'
activesupport (6.0.3.7) lib/active_support/notifications.rb:180:in `block in instrument'        
activesupport (6.0.3.7) lib/active_support/notifications/instrumenter.rb:24:in `instrument'     
activesupport (6.0.3.7) lib/active_support/notifications.rb:180:in `instrument'
actionpack (6.0.3.7) lib/action_controller/metal/instrumentation.rb:32:in `process_action'      
actionpack (6.0.3.7) lib/action_controller/metal/params_wrapper.rb:245:in `process_action'      
activerecord (6.0.3.7) lib/active_record/railties/controller_runtime.rb:27:in `process_action'  
actionpack (6.0.3.7) lib/abstract_controller/base.rb:136: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/routing/mapper.rb:18:in `block in <class:Constraints>' 
actionpack (6.0.3.7) lib/action_dispatch/routing/mapper.rb:48: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:40: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/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'
- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2021-07-03 23:01:17 +0900 ===
```

該当のregistrationファイルは以下です。

```ruby:registration.rb
class Api::V1::Auth::RegistrationsController < DeviseTokenAuth::RegistrationsController
  private
    def sign_up_paramss
      params.require(:registration).permit(:registration,:name,:email, :img, :password, :password_confirmation,:address)
    end 
      
    def account_update_params
      params.require(:registration).permit(:name, :registration, :email, :img,:session)
    end
end
```

<h2>解決策</h2>
ストロングパラメータのメソッド名が間違っていました。
今回の例ではわかりやすくssと書きましたが、実際に遭遇したときは真贋分からず、サイトからメソッド名をコピペしなおしたら解決しました。

```ruby:registration.rb
class Api::V1::Auth::RegistrationsController < DeviseTokenAuth::RegistrationsController
  private
    def sign_up_params
      params.require(:registration).permit(:registration,:name,:email, :img, :password, :password_confirmation,:address)
    end 
      
    def account_update_params
      params.require(:registration).permit(:name, :registration, :email, :img,:session)
    end
end
```

<h2>参考</h2>

https://devise-token-auth.gitbook.io/devise-token-auth/usage

https://nanayaku.com/rails-nomethoderror-nilclass/