Skip to content

Instantly share code, notes, and snippets.

@leobossmann
Created September 15, 2015 12:28
Show Gist options
  • Save leobossmann/efdf34b11acc7f9a69f1 to your computer and use it in GitHub Desktop.
Save leobossmann/efdf34b11acc7f9a69f1 to your computer and use it in GitHub Desktop.
Rake task to create strong parameters definition
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