[ANN] Permissionable Attributes Plugin for Rails
I’ve had to do a couple sites now where I have needed to set permissions on a lot of attributes on a model. So, for example on a community site users can choose to show there information to other people based on if the person is a friend, member of the site, or just some random person on the internet. While doing something like this is pretty straight forward in rails I wanted something a little more simpler… Something a little more declarative.. Something like this:
has_attributes_with_permissions do |config|
config.attributes = %w[first_name last_name email age]
config.permissions = [:viewable_by_public, :viewable_by_friends, :viewable_by_no_one]
config.permission_defaults = {:first_name => :viewable_by_friends, :all => :viewable_by_public}
end
As you probably gathered from this post’s title, I ended up creating a plugin to allow you to declare attributes with permissions just like that.
Methods are generated for your use and enjoyment, and you can optionally use a single integer to store all of your attributes permissions (a’la bitmasks.)
For more details check out the plugin’s new homepage:
http://code.google.com/p/permissionable-attributes/
Specifically, the README:
http://permissionable-attributes.googlecode.com/svn/trunk/README
To give the plugin a whirl, the code actually lives here:
http://permissionable-attributes.googlecode.com/svn/trunk/
You’re currently reading “[ANN] Permissionable Attributes Plugin for Rails”, an entry on Ben Mabey
- Published:
- 10.23.07 / 10pm
- Tags:
- Post Navigation:
- « BDD your C
I’m Batman »