views:

33

answers:

1

I have an app where there are multiple "Admin-ish" roles. Imagine you have a super-admin that can edit anything, and also a site-admin that can edit any information about his site.

So both admin/sites and siteadmin/sites are basically the exact same view.

What's the right way to set this up (views/controllers)? I'm trying to keep things as DRY as possible.

A: 

I'm a huge fan of the Rails Authorization plugin

This allows you to easily assign roles to objects and use blocks to grant access.

@a.has_role('admin')
@b.has_role('super_admin')

permit "admin or super_admin' do
  # Show admin and super_admin stuff
end

permit 'super_admin' {}

You can also grant access on other objects or classes.

@user.has_role('photographer', @photo)
@user.has_role('news_poster', NewsPost)
Ariejan
So then how would you break apart views that had 90% congruency? Tons of partials? Logic in the views?
Jeff
Jeff, you could do it either way. I've done both. It will really depends on just how much overlap there is and whether they are likely to stay similar or if they will tend to diverge in the future.
Peter Wagenet