# Mixin in ERB Templates

**URL:** <https://www.ruby-forum.com/t/mixin-in-erb-templates/78913>\
**Category:** Rails\
**Created:** [December 10, 2006, 1:52pm UTC](https://www.ruby-forum.com/t/mixin-in-erb-templates/78913 "2006-12-10T13:52:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdaoust](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mdaoust](https://www.ruby-forum.com/u/mdaoust)\
**Post date:** [December 10, 2006, 1:52pm UTC](https://www.ruby-forum.com/t/mixin-in-erb-templates/78913/1 "2006-12-10T13:52:13Z")

</div>

Hi All,

I have some ERB .rhtml templates in my rails CMS app. The user selects  
a template for each page through the CMS administration UI. So the list  
of available templates is presented in a drop-down.

I don’t want to create a ‘template’ model which sits in my DB as it is  
overkill. What I want to do is somehow define meta data about each  
template (namely a title and description) as some class variables  
inside the ERB .rhtml templates such as:

\<%  
require ‘registerable\_asset’  
include RegisterableAsset  
register ‘Name of Template’  
description ‘This template is a default template’  
%\>

 ... rest of template ... 

So I’ve created a module (registerable\_asset) which appends these  
features as class variables and tried to include this in the template  
file using the standard (include …), but I get an error:

undefined method `include’ for #\<#Class:0x256a8dc:0x256a8b4\>

I assume that I am putting the ‘include’ statement in the wrong place  
but I’m not sure where to put it. Does anyone have any suggestions?

Many Thanks

Mark D.

---

<div class="post-metadata">

**Author:** ![mdaoust](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mdaoust](https://www.ruby-forum.com/u/mdaoust)\
**Post date:** [December 10, 2006, 2:15pm UTC](https://www.ruby-forum.com/t/mixin-in-erb-templates/78913/2 "2006-12-10T14:15:07Z")

</div>

Put this file in the lib directory and Rails will find the class  
automatically. Nor require required. 😉

---

<div class="post-metadata">

**Author:** ![mdaoust](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mdaoust](https://www.ruby-forum.com/u/mdaoust)\
**Post date:** [December 10, 2006, 5:12pm UTC](https://www.ruby-forum.com/t/mixin-in-erb-templates/78913/3 "2006-12-10T17:12:02Z")

</div>

Thanks, I didn’t know that. However, it seems to be the ‘include’  
statement that is causing trouble…
