Last active
December 17, 2024 11:42
-
-
Save yamamoto-works/2352d7216116d1e4ef80d4262a1c5af7 to your computer and use it in GitHub Desktop.
RailsのParamsで動的にpermitする
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
params = params.require(:Form名).permit([許可したいパラメーター名]) | |
if 何らかの条件 | |
params[:動的にpermitしたいパラメーター名] = ActionController::Parameters.new.permit! | |
end | |
params | |
# こっちのほうが楽 | |
new_params = params.require(:Form名).permit([許可したいパラメーター名]) | |
if 何らかの条件 | |
new_params.merge(prams.permit([:動的にpermitしたいパラメーター名])) | |
end | |
new_params |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment