When including
gem 'strong_parameters'
gem 'rails-api'
together in my Gemfile, calling params.require like
private
def user_params
params.require(:user).permit(:first_name, :last_name)
end
fails with the following error on the require() call.
TypeError:
can't convert Symbol into String
The backtrace shows strong_parameters‘ ActionController::StrongParameters‘ require() method is never hit.
I spent too long on this one, so I figured I’d share here to hopefully save someone else a bit of time.
The error above comes from the
require()method inActiveSupport::Dependencies::Loadablebeing executed when callingstrong_parametersinjectsActionController::StrongParametersintoActionController::Baseat the bottom of this file withThe
rails-apigem requires your app’sApplicationControllerextendActionController::APIin favor ofActionController::BaseThe application controllers don’t know anything about
ActionController::StrongParametersbecause they’re not extending the classActionController::StrongParameterswas included within. This is why therequire()method call is not calling the implementation inActionController::StrongParameters.To tell
ActionController::APIaboutActionController::StrongParametersis as simple as adding the following to a file inconfig/initializers.