Not sure if this applies to your example but since the permission is a full ruby method you can use any ruby code. You might want to separate out complicated logic into a helper method for one. Secondly, early termination can simplify a lot of permissions code:
return false if field.in?(blacklisted_fields) return true if state.active? # further tests below On Tuesday, October 6, 2015 at 11:58:04 AM UTC-6, Nathan Peters wrote: > > I have a number of view_permitted declarations kind of like this: > > > if (self.state == 'active') then > > return true > > end > > > Which works but is getting a bit complicated as I have some detailed > permission logic. But now I am needing to *also* disable views on certain > fields. Something like this works: > > > if (self.state == 'active') then > > if(field == :userdescription) then > > return false > > end > > return true > > end > > > ...and records with 'active' state are shown but the :userdescription > field is blocked. But I have a number of fields to block. I considered > seeing if I can do something like field.in?(array_of_fields) and keep the > large field lists out of the permission code. But it's probably going to > leave me with some extremely non-elegant code (not that it is great now). > > > Is there a better way to handle something like this? > > > Thanks, > > Nathan > -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/hobousers. For more options, visit https://groups.google.com/d/optout.
