# Inheriting behaviours

**URL:** <https://www.ruby-forum.com/t/inheriting-behaviours/66793>\
**Category:** Radiant CMS\
**Created:** [August 29, 2006, 11:42am UTC](https://www.ruby-forum.com/t/inheriting-behaviours/66793 "2006-08-29T11:42:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 29, 2006, 11:42am UTC](https://www.ruby-forum.com/t/inheriting-behaviours/66793/1 "2006-08-29T11:42:43Z")

</div>

Is it possible to make children inherit the behaviour of the parent?  
For instance it would be nice for a blog site if all the children of  
‘posts’ could automatically have a ‘comments’ behaviour.

I’m making a site where this functionality would come in handy.

What I’m also wondering if there’s a way to make default page\_parts  
for children. To stay with the blog example: children of ‘posts’  
would have the ‘extended’ page\_part by default, but other pages would  
not.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 9, 2006, 5:10pm UTC](https://www.ruby-forum.com/t/inheriting-behaviours/66793/2 "2006-09-09T17:10:30Z")

</div>

jeroen janssen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Is it possible to make children inherit the behaviour of the parent?  
> For instance it would be nice for a blog site if all the children of  
> ‘posts’ could automatically have a ‘comments’ behaviour.

Yes, thats exactly what i need too… If its not possible i think it  
should be added in the future…

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 9, 2006, 5:38pm UTC](https://www.ruby-forum.com/t/inheriting-behaviours/66793/3 "2006-09-09T17:38:31Z")

</div>

Johannes Ziemke wrote:

> jeroen janssen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Is it possible to make children inherit the behaviour of the parent?  
> > For instance it would be nice for a blog site if all the children of  
> > ‘posts’ could automatically have a ‘comments’ behaviour.
> 
> Yes, thats exactly what i need too… If its not possible i think it  
> should be added in the future…

Behaviors support the define\_child\_tags class method. So if all you want  
to do is add tags that are accessible on the children, you can easily do  
that like this:

class BlogBehavior \< Behavior::Base  
define\_child\_tags do  
tag “hello” do  
“hello world!”  
end  
end  
end

Matt McCray made a plugin which adds support for Rails like before and  
after filters which would give you the ability to make other changes to  
child pages.

–  
John L.  
[http://wiseheartdesign.com](http://wiseheartdesign.com)
