Ezra''s acl_system access control plugin creates a helper method. This
is
a direct cut-and-paste from that code:
# restrict_to "admin | moderator" do
# link_to "foo"
# end
def restrict_to(logicstring, context = {})
return false if current_user.nil?
result = ''''
if permit?(logicstring, context)
result = yield if block_given?
end
result
end
Josh Kieschnick wrote:> in the Rails Recipes book there is a chapter on role-based
> authentication. it basically set up priviliges based on what page the
> user was able to access. i went through the chapter and felt like i got
> a pretty good understanding of how to do it.
>
> now i am needing something a little more advanced though. instead of a
> per page (or action) i would like to have certain sections on a page
> either show or be hidden based on the role of the user. the best example
> i can think of would be on the typo blog. there is an edit button on
> each post that only shows up if the user is logged in.
>
> for the most part, i think something like this would be pretty easy, but
> i''m mainly posting this because i would like to keep my code clean
and
> not put a bunch of useless conditionals and actions in my view.
>
>