Hi Nathan,
You could create an external file/service like this:
class MyModelPolicy
def initialize(model)
@model = model
end
def view_permitted?
end
def update_permitted?
end
end
This way in your model you could have:
def view_permitted
MyModelPolicy.new(self).view_permitted?
end
The main improvements of using external services is that you can test
them by themselves, and you remove clutter from your models.
Warm regards,
Ignacio
El 06-10-2015 a las 19:58, Nathan Peters escribió:
> 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]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/d/optout.
--
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.