Skip to content

Instantly share code, notes, and snippets.

@iHiD
Created June 10, 2012 13:49
Show Gist options
  • Save iHiD/2905710 to your computer and use it in GitHub Desktop.
Save iHiD/2905710 to your computer and use it in GitHub Desktop.
Security Article Part 2 - 5
# Migration
create_table :users do |t|
t.boolean :can_do_dangerous_things, null: false
#...
t.timestamps
end
class User < ActiveRecord::Base
# Blacklisting attribute
attr_protected :can_do_dangerous_things
before_create do
return true if @permissions_set
self.permissions = {
:can_do_dangerous_things => false
#...
}
true
end
def permissions=(hash)
self.can_do_dangerous_things = hash[:can_do_dangerous_things]
#...
@permissions_set = true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment