From e7d7efef68c033adca1bce3dd34aa25ca174a5e6 Mon Sep 17 00:00:00 2001 From: jbranchaud Date: Mon, 4 May 2020 19:58:46 -0500 Subject: [PATCH] Add Temporarily Disable strong_params as a rails til --- README.md | 3 ++- rails/temporarily-disable-strong-params.md | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 rails/temporarily-disable-strong-params.md diff --git a/README.md b/README.md index e5680f4..665afff 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ and pairing with smart people at Hashrocket. For a steady stream of TILs, [sign up for my newsletter](https://tinyletter.com/jbranchaud). -_909 TILs and counting..._ +_910 TILs and counting..._ --- @@ -579,6 +579,7 @@ _909 TILs and counting..._ - [Show Pending Migrations](rails/show-pending-migrations.md) - [Show Rails Models With Pry](rails/show-rails-models-with-pry.md) - [Show Rails Routes With Pry](rails/show-rails-routes-with-pry.md) +- [Temporarily Disable strong_params](rails/temporarily-disable-strong-params.md) - [Test If An Instance Variable Was Assigned](rails/test-if-an-instance-variable-was-assigned.md) - [Truncate Almost All Tables](rails/truncate-almost-all-tables.md) - [Update Column Versus Update Attribute](rails/update-column-versus-update-attribute.md) diff --git a/rails/temporarily-disable-strong-params.md b/rails/temporarily-disable-strong-params.md new file mode 100644 index 0000000..80a283a --- /dev/null +++ b/rails/temporarily-disable-strong-params.md @@ -0,0 +1,22 @@ +# Temporarily Disable strong_params + +I was recently doing a Rails upgrade. This old version of the app wasn't +prepared to deal with `strong_params` right away. I already had a pile of +migration path TODOs and fixes on top of addressing the `strong_params` issue. +I decided to put off dealing with `strong_params` by adding this line the main +controller. + +```ruby +# app/controllers/application_controller.rb +def params + request.parameters +end +``` + +This bypasses the `strong_params` check for all controllers inheriting from +`ApplicationController`. + +Remember, this is a _temporary_ fix. You'll eventually want to adhere to +`strong_params` for your mass assignments. + +[source](https://stackoverflow.com/a/41163978/535590)