Forum: Ruby on Rails Mixins?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Ff7c968ec96d769974df09dc453eb746?d=identicon&s=25 Sean Blezard (Guest)
on 2006-04-11 13:47
(Received via mailing list)
As is often the case when I tackle a new platform/language, I get the
picture very quickly (because frameworks are frameworks are frameworks)
its the nitty-gritty of the language that bogs me down...

So I have some similar methods on a few of my model classes that I
wanted to
push into a helper. Now I reckoned that the Ruby way was to create a
and mix it in with include. However, I can't get it to work

In the first instance I put it straight into the models directory:

module FieldHelper
  def validate_field
    if template_field.mandatory? && (!field_value ||
      errors.add(, _(''))

Now in the model I have this :

require "field_helper"

class SchemeAccountField < ActiveRecord::Base
  include FieldHelper

  def validate


So basically I want to mix in very similar validation rules.

However, what I get is:

undefined local variable or method `validate_field' for ...

I'm obviously missing something obvious and/or being stupid but that's
nature of the game with a new language I suppose.

Any help out there?
Ff7c968ec96d769974df09dc453eb746?d=identicon&s=25 Sean Blezard (Guest)
on 2006-04-11 16:15
(Received via mailing list)
OK sorted it. I forgot to put the module in a file in the lib
missed that bit. I can now include it in my model classes.
This topic is locked and can not be replied to.