Suppose that, we have Attempt model and we have serialized an attribute in attempt.rb like this
Now, if you are creating attempt through strong parameters in controller -
And you have permitted response attribute in strong parameters like this
OR
Above strong parameters will save response as nil or blank. In this scenario we have to permit keys of serialized attributes in strong parameter
class Attempt < ApplicationRecord #==== Serializations ================== serialize :response end
Now, if you are creating attempt through strong parameters in controller -
Attempt.create(attempts_params)
And you have permitted response attribute in strong parameters like this
def attempts_params params.require(:attempt).permit(:response) end
OR
def attempts_params params.require(:attempt).permit(:response => {}) end
Above strong parameters will save response as nil or blank. In this scenario we have to permit keys of serialized attributes in strong parameter
def attempts_params response_keys = params[:attempt][:response].keys params.require(:attempt).permit(response: response_keys) end