Skip to content

Instantly share code, notes, and snippets.

@nthj
Forked from cail/accessible_block.rb
Created March 30, 2011 20:30
Show Gist options
  • Save nthj/895232 to your computer and use it in GitHub Desktop.
Save nthj/895232 to your computer and use it in GitHub Desktop.
module AccessibleBlock
extend ActiveSupport::Concern
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment