Skip to content

Instantly share code, notes, and snippets.

@cail
Created July 8, 2010 13:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cail/467999 to your computer and use it in GitHub Desktop.
Save cail/467999 to your computer and use it in GitHub Desktop.
module AccessibleBlock
module ClassMethods
@accessible_block = false
def key(*arguments, &block)
super
attr_accessible arguments[0] if @accessible_block
end
def attr_accessible(*attrs)
if block_given?
@accessible_block = true
yield
@accessible_block = false
else
super
end
end
end
end
autoload :AccessibleBlock, 'lib/accessible_block'
class Model
include MongoMapper::Document
plugin AccessibleBlock
attr_accessible do
key :somekey
key :another key
end
key :private_key
end
@jnunemaker
Copy link

Might want to call super before attr accessible. I would have to check but i think it is relatively important that key returns the key.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment