Created
September 1, 2013 12:50
-
-
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
This file contains 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
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