# Before\_create event or method

**URL:** <https://www.ruby-forum.com/t/before-create-event-or-method/138725>\
**Category:** Rails\
**Created:** [May 27, 2008, 8:51am UTC](https://www.ruby-forum.com/t/before-create-event-or-method/138725 "2008-05-27T08:51:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pankaj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a9adbd/32.png) [@pankaj](https://www.ruby-forum.com/u/pankaj)\
**Post date:** [May 27, 2008, 8:51am UTC](https://www.ruby-forum.com/t/before-create-event-or-method/138725/1 "2008-05-27T08:51:30Z")

</div>

I have multiple models which have certain(same) action(let us call it  
action1) to be performed on before\_create, and other common  
funcionallity.  
Also in only certain model action2 is also to be performed.

class Model1  
def before\_create  
#do action1  
#do action2  
end  
#other commmon functionallity  
end

class Model2  
def before\_create  
#do action1  
end  
#other commmon functionallity  
end

class Model3  
def before\_create  
#do action1  
end

#other commmon functionallity  
end

Now action1 and 'other common functionallity" can be seperated into a  
seperate module.  
But what about “action2” in Model1.  
If before\_create was an event then a chain of event handeller could be  
assigned. But before\_create is a method. What to do?  
Thanks,  
Pankaj

---

<div class="post-metadata">

**Author:** ![pankaj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a9adbd/32.png) [@pankaj](https://www.ruby-forum.com/u/pankaj)\
**Post date:** [May 27, 2008, 1:53pm UTC](https://www.ruby-forum.com/t/before-create-event-or-method/138725/2 "2008-05-27T13:53:51Z")

</div>

before\_create can be a method but I usually use it differently. IE, you  
can do this:

class Model1  
before\_create :action1  
before\_create :action2  
#other commmon functionallity  
end

class Model2  
before\_create :action1  
#other commmon functionallity  
end

class Model3  
before\_create :action1

#other commmon functionallity  
end

I believe using it this way allows for the desired “event chaining”  
behavior.
