OwnedModel module completed

2010/05/10 at 3:50 pm (2010)

Today I finished my OwnedModel module and added owned_module function to remove some more duplication.
module OwnedModel
def create_permitted?
acting_user.signed_up?
end
def update_permitted?
owned?
end
def edit_permitted?(field)
owned_soft?
end
def destroy_permitted?
owned?
end
def view_permitted?(field)
owned_soft?
end
protected
def owned?
owner_is?(acting_user) and !owner_changed?
end
def owned_soft?
owner_is?(acting_user)
end
def must_be_owned
errors.add(:owner, "must be current_user") unless owned?
end
def included
validate_presence_of :owner
end
end
def owned_model(owner_class)
belongs_to :owner, :class_name => owner_class
never_show :owner
attr_readonly :owner
include OwnedModel
end

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: