Created
September 15, 2015 12:28
-
-
Save leobossmann/efdf34b11acc7f9a69f1 to your computer and use it in GitHub Desktop.
Rake task to create strong parameters definition
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
namespace :whatever do | |
desc "Outputs strong parameters for all of a model's attributes, ready to be pasted. Use with caution, it permits *everything*" | |
task :strong_params,[:model] => :environment do |t, args| | |
puts "\nprivate\n\n" | |
puts "def #{args.model.underscore}_params" | |
attributes = " :" + args.model.constantize.new.attributes.except("id", "created_at", "updated_at").keys.join(",\n :") | |
puts " params.require(:#{args.model.underscore}).permit(\n#{attributes}\n)" | |
puts "end" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment