Skip to content

Instantly share code, notes, and snippets.

@ingemar
Created September 1, 2013 12:50
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ingemar/6404260 to your computer and use it in GitHub Desktop.
Save ingemar/6404260 to your computer and use it in GitHub Desktop.
A DRY way to deal with strong parameters in Ruby on Rails 4 together with the excellent gem decent_exposure
module ParamsFor
def params_for(model, *attributes)
return if method_defined? "#{model}_params"
define_method "#{model}_params" do
params.require(model).permit attributes
end
end
end
# class ApplicationController < ActionController::Base
# extend ::ParamsFor
#
# decent_configuration do
# strategy DecentExposure::StrongParametersStrategy
# end
# end
# class UsersController < ApplicationController
# expose :user, attributes: :user_params
#
# params_for :user, :name, :email
# end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment