# Model methods

**URL:** <https://www.ruby-forum.com/t/model-methods/146646>\
**Category:** Rails\
**Created:** [August 23, 2008, 3:53pm UTC](https://www.ruby-forum.com/t/model-methods/146646 "2008-08-23T15:53:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![idk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e9a140/32.png) [@idk](https://www.ruby-forum.com/u/idk)\
**Post date:** [August 23, 2008, 3:53pm UTC](https://www.ruby-forum.com/t/model-methods/146646/1 "2008-08-23T15:53:54Z")

</div>

Hello, I’m pretty new to ruby and rails.

This is part of my code:

class Command \< ActiveRecord::Base  
has\_many :executions

def with\_extension(ext)  
Extension.all(:include =\> :command,  
:conditions =\> { :suffix =\> ext})  
end  
end

And later in my controller I try to do this:  
@commands = Command.with\_extension(‘all’)

But I gt an error:  
undefined method `with\_extension’ for #Class:0xb6eaecbc

That was the first problem, the second is that I’m nut sure how  
the with\_extension function should look like.

Here’s my extension schema:  
create\_table “extensions”, :id =\> false do |t|  
t.string “suffix”  
t.integer “command\_id”  
end

I want to get a list of commands which have a suffix:command mapping.

Niklas U.  
thanks for your time  
and wishes everyone  
Happy Programming!

---

<div class="post-metadata">

**Author:** ![idk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e9a140/32.png) [@idk](https://www.ruby-forum.com/u/idk)\
**Post date:** [August 23, 2008, 4:21pm UTC](https://www.ruby-forum.com/t/model-methods/146646/2 "2008-08-23T16:21:25Z")

</div>

with\_extension must be defined as class method

def self.with\_extension  
…  
end
