Skip to content

Instantly share code, notes, and snippets.

@asmega
Created October 23, 2011 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmega/1307343 to your computer and use it in GitHub Desktop.
Save asmega/1307343 to your computer and use it in GitHub Desktop.
rails mass assignment checker
Dir.glob("#{Rails.root}/app/models/*.rb").collect{|m| m.split("/").last.split(".").first.camelize.constantize }
models = ActiveRecord::Base.subclasses.collect(&:name).collect(&:constantize)
models.each{|m| puts m; print "Columns: #{m.column_names}"; puts ""; print "Protected: #{m.attr_protected.to_a}"; puts ""; print "Accessible: #{m.attr_accessible.to_a}"; puts "\n\n" }
# example output
#
#User
#Columns: ["id", "email", "encrypted_password", "salt", "confirmation_token", "remember_token", #"created_at", "updated_at", "company_id", "status"]
#Protected: ["id", "type", "status", "company_id"]
#Accessible: []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment