# Validation Idiom

**URL:** <https://www.ruby-forum.com/t/validation-idiom/130054>\
**Category:** Rails\
**Created:** [February 25, 2008, 1:03am UTC](https://www.ruby-forum.com/t/validation-idiom/130054 "2008-02-25T01:03:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![corywilkerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@corywilkerson](https://www.ruby-forum.com/u/corywilkerson)\
**Post date:** [February 25, 2008, 1:03am UTC](https://www.ruby-forum.com/t/validation-idiom/130054/1 "2008-02-25T01:03:15Z")

</div>

All - is there a standard pattern for the following case? My domain is  
pretty unique so let me use an analogy to try and better convey the  
problem.

Let’s assume that a “director” owns a “series” and that an  
“administrator” or “director” can add information (actors, an episode,  
whatever) to that “series”. So, for a given season (Let’s say it’s Lost  
and JJ Abrams is the director), JJ wants to login to this app and say  
“add a new episode to Lost.”

I need to ensure that JJ has the rights to add this episode or actor to  
the series he’s wishing to add it to. In other words, I need to say -  
if JJ (current\_user) is the director of this series, then let him.

That said, let’s say I have an ‘episode’ object - and JJ has gone and  
created a new instance. I’m guessing the best way to make sure that the  
current user (JJ) has rights to create this episode (before saving) is  
to override validate and basically say:

def validate  
errors.add\_to\_base(“no no”) unless current\_user (jj) owns the series  
we’re trying to associate this episode to  
end

Does this question make sense? Hope so.

---

<div class="post-metadata">

**Author:** ![corywilkerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@corywilkerson](https://www.ruby-forum.com/u/corywilkerson)\
**Post date:** [February 25, 2008, 2:35am UTC](https://www.ruby-forum.com/t/validation-idiom/130054/2 "2008-02-25T02:35:00Z")

</div>

it is not validation issue, it should not go to model at all.  
before\_filter in controller or decent acl plugin will do the job

On 25 ÆÅ×, 02:03, Cory W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![corywilkerson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/aca169/32.png) [@corywilkerson](https://www.ruby-forum.com/u/corywilkerson)\
**Post date:** [February 25, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/validation-idiom/130054/3 "2008-02-25T19:53:04Z")

</div>

There’s a great Rails Recipe ([Pragmatic Bookshelf: By Developers, For Developers](http://www.pragprog.com/titles/fr_rr/))  
that covers basic access control using users, roles, and rights. I  
don’t have it nearby, but I’d highly recommend reading it in your  
case.

-Kyle
