Basic Info
- rails_param Version: 1.3.1
- Ruby Version: 3.2.1
- Rails Version: 7.0.x
Issue description
The param! methods does not call params.permit over validated parameters, this means that after the validation block we need to manually permit and extract only the required fields.
e.g.
param! :reaction, Hash, required: true do |r|
r.param! :note, String, required: false, blank: true
r.param! :like, :boolean, required: false
r.param! :love, :boolean, required: false
r.param! :reject, :boolean, required: false
end
# or with a separate method if you prefer
reaction_params = params.permit(reaction: [:like, :love, :reject, :note])
This is very repetitive and error-prone when deleting/adding new fields and could lead to dangerous errors.
The README is not very clear about this, from a first read I understood that I could use this gem and forget about the params.permit but now I figured out it's not like that.
I propose to automatically permit params (and nested params) based on the fields declared in param! by overriding the params variable or using a new instance variable such as @sanitized_params, @rails_params or whatever you prefer.
I'd like to open a PR if you like this idea, otherwise I will just keep the fork for me.
What do you think?
Basic Info
Issue description
The
param!methods does not callparams.permitover validated parameters, this means that after the validation block we need to manually permit and extract only the required fields.e.g.
This is very repetitive and error-prone when deleting/adding new fields and could lead to dangerous errors.
The README is not very clear about this, from a first read I understood that I could use this gem and forget about the
params.permitbut now I figured out it's not like that.I propose to automatically permit params (and nested params) based on the fields declared in
param!by overriding the params variable or using a new instance variable such as@sanitized_params,@rails_paramsor whatever you prefer.I'd like to open a PR if you like this idea, otherwise I will just keep the fork for me.
What do you think?