Skip to content

Instantly share code, notes, and snippets.

@kavu
Created January 3, 2013 16:05
Show Gist options
  • Save kavu/4444521 to your computer and use it in GitHub Desktop.
Save kavu/4444521 to your computer and use it in GitHub Desktop.
attr_scanner.rb by@joernchen
#!/usr/bin/env ruby
#
# Mass assignment scanner for Ruby on Rails
# should be run from rails console in production
# environment.
#make sure all models are loaded
Dir[Rails.root + 'app/models/**/*.rb'].each { |path| require path }
models = ActiveRecord::Base.subclasses
## for mongoid:
# ObjectSpace.each(Class).select { |c| c < Mongoid::Document }
## (does not work in all rubies)
models.each do |m|
mod = m.new
puts "All attributes for model #{m}:"
mod.attributes.each_key do |k|
puts "\t#{k}"
end
puts "Protected attributes for model #{m}:"
m.protected_attributes.each do |p|
puts "\t#{p}"
end
puts "Accessible attributes for model #{m}:"
m.accessible_attributes do |a|
puts "\t#{a}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment