# Undefined method \`current' for Personnel:Class

**URL:** <https://www.ruby-forum.com/t/undefined-method-current-for-personnel-class/67263>\
**Category:** Rails\
**Created:** [September 1, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/undefined-method-current-for-personnel-class/67263 "2006-09-01T18:10:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [September 1, 2006, 6:10pm UTC](https://www.ruby-forum.com/t/undefined-method-current-for-personnel-class/67263/1 "2006-09-01T18:10:52Z")

</div>

I can’t quite figure out how I can make this work properly.

I’m in my login\_controller.rb

If I use  
cond = EZ::Where::Condition.new  
cond = “term\_date IS NULL”.to\_c + c{employment\_type === [‘CLIENT’,  
‘CSW’, ‘F/T’,‘P/T’, ‘INT’, ‘PRN’]}  
@personnel = Personnel.find(:all,  
:conditions =\> cond.to\_sql,  
:order =\> ‘last\_name, first\_name’)

This works but is not very dry since I use this in multiple places.

So in my personnel.rb model, I have something identical…  
def current  
cond = EZ::Where::Condition.new  
cond = “term\_date IS NULL”.to\_c + c{employment\_type === [‘CLIENT’,  
‘CSW’, ‘F/T’,‘P/T’, ‘INT’, ‘PRN’]}  
Personnel.find(:all,  
:conditions =\> cond.to\_sql,  
:order =\> ‘last\_name, first\_name’)  
end

but if I try to use  
@personnel = Personnel.current

in my login\_controller.rb, I get the 'undefined method ‘current’ for  
Personnel:Class error - even if I 'require “personnel” in my login.rb  
model (which I wouldn’t think necessary since login.rb  
‘has\_one :personnel’)

Why doesn’t the definition in the personnel model work in another  
controller?

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [September 1, 2006, 6:26pm UTC](https://www.ruby-forum.com/t/undefined-method-current-for-personnel-class/67263/2 "2006-09-01T18:26:54Z")

</div>

you’re trying to call an instance method as a class method

make it a class method

def self.current  
…  
end

Chris

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [September 1, 2006, 6:36pm UTC](https://www.ruby-forum.com/t/undefined-method-current-for-personnel-class/67263/3 "2006-09-01T18:36:56Z")

</div>

Hello Craig,  
Surely you mean ‘def Personnel.current’ since your using it as a  
class method … no ?

```
Regards
Stef
```

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [September 1, 2006, 6:36pm UTC](https://www.ruby-forum.com/t/undefined-method-current-for-personnel-class/67263/4 "2006-09-01T18:36:56Z")

</div>

> ```
> @personnel = Personnel.current
> 
> ```

You’ve defined current as an instance method, but are trying to access  
it as  
a class method. One way to define it as a class method is to:

def self.current  
…  
end

then Personnel.current will be “seen”.

On a side note, you may want to use Personnel.find(:first) as  
Personnel.find(:all)  
will return an array and I think you just want a single personnel  
instance.

–  
Andrew S.

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [September 1, 2006, 7:05pm UTC](https://www.ruby-forum.com/t/undefined-method-current-for-personnel-class/67263/5 "2006-09-01T19:05:06Z")

</div>

On Fri, 2006-09-01 at 12:22 -0400, Andrew S. wrote:

> then Personnel.current will be “seen”.

* * *

## it’s sometimes amazing that I have gotten as much done as I have - even after reading/re-reading AWDWR and R4R 😉

> On a side note, you may want to use Personnel.find(:first) as  
> Personnel.find(:all) will return an array and I think you just want a  
> single personnel instance.

* * *

No, in this instance, I needed a list of only ‘current’ personnel (i.e.  
termination date is NULL and employee types and not volunteers/board  
members, etc.

Thanks, self.current was indeed the solution.

Craig

---

<div class="post-metadata">

**Author:** ![craigrails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c2a13f/32.png) [@craigrails](https://www.ruby-forum.com/u/craigrails)\
**Post date:** [September 1, 2006, 6:55pm UTC](https://www.ruby-forum.com/t/undefined-method-current-for-personnel-class/67263/6 "2006-09-01T18:55:04Z")

</div>

I see - said the blind man

thanks - it works

Craig
