diff options
author | blackst0ne <blackst0ne.ru@gmail.com> | 2018-04-08 07:35:30 +0300 |
---|---|---|
committer | blackst0ne <blackst0ne.ru@gmail.com> | 2018-04-08 07:35:30 +0300 |
commit | eddf3febd7e78a442a0b2fbd36d7b92ba769f4a5 (patch) | |
tree | 17ce078c15b18cf28a2c0e65afae1411935168cf /app/helpers/safe_params_helper.rb | |
parent | dd552d06f6e39d5e6138a33bd7c1bffb2d3dbb1d (diff) |
[Rails5] Add `safe_params` helper
Rails 5.0 requires to explicitly permit attributes when building a URL
using current `params` object.
The `safe_params` helper allows developers to just call `safe_params.merge(...)`
instead of manually adding `permit` to every call.
https://github.com/rails/rails/pull/20868
Diffstat (limited to 'app/helpers/safe_params_helper.rb')
-rw-r--r-- | app/helpers/safe_params_helper.rb | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/app/helpers/safe_params_helper.rb b/app/helpers/safe_params_helper.rb new file mode 100644 index 00000000000..feacd3eef4a --- /dev/null +++ b/app/helpers/safe_params_helper.rb @@ -0,0 +1,11 @@ +module SafeParamsHelper + # Rails 5.0 requires to permit parameters if used in url helpers. + # User this helper when generating links with `params.merge(...)` + def safe_params + if params.respond_to?(:permit!) + params.except(:host, :port, :protocol).permit! + else + params + end + end +end |