# How to invoke model methods in controller & vice versa

**URL:** <https://www.ruby-forum.com/t/how-to-invoke-model-methods-in-controller-vice-versa/98647>\
**Category:** Rails\
**Created:** [July 17, 2006, 9:37am UTC](https://www.ruby-forum.com/t/how-to-invoke-model-methods-in-controller-vice-versa/98647 "2006-07-17T09:37:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![narayana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f6c823/32.png) [@narayana](https://www.ruby-forum.com/u/narayana)\
**Post date:** [July 17, 2006, 9:37am UTC](https://www.ruby-forum.com/t/how-to-invoke-model-methods-in-controller-vice-versa/98647/1 "2006-07-17T09:37:55Z")

</div>

hello

how to invoke model methods in controller & vice versa  
please explain with examples

advance thanx

---

<div class="post-metadata">

**Author:** ![narayana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f6c823/32.png) [@narayana](https://www.ruby-forum.com/u/narayana)\
**Post date:** [July 17, 2006, 9:58am UTC](https://www.ruby-forum.com/t/how-to-invoke-model-methods-in-controller-vice-versa/98647/2 "2006-07-17T09:58:54Z")

</div>

You shouldn’t be invoking any controllers methods from your models,  
but to invoke a method from a controller on a model you do it the  
same way you do in every other ruby class.

obj = ModelName.new

go from there.

Thank You,  
Ben J.  
E: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![narayana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f6c823/32.png) [@narayana](https://www.ruby-forum.com/u/narayana)\
**Post date:** [July 17, 2006, 10:17am UTC](https://www.ruby-forum.com/t/how-to-invoke-model-methods-in-controller-vice-versa/98647/3 "2006-07-17T10:17:39Z")

</div>

hai  
first of all thx to u for explaining  
i did the same way like that ur qouted  
even am calling the method in model  
by doing  
s=Shortform.price # shortform is the model class & price is the method  
in it  
but the error was arise error: undefine method price in shortform  
am checked the spelling & am define the particular method also  
but the error was arise  
plz help me Mr.

Thx

Ben J. wrote:

> You shouldn’t be invoking any controllers methods from your models,  
> but to invoke a method from a controller on a model you do it the  
> same way you do in every other ruby class.
> 
> obj = ModelName.new
> 
> go from there.
> 
> Thank You,  
> Ben J.  
> E: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![narayana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f6c823/32.png) [@narayana](https://www.ruby-forum.com/u/narayana)\
**Post date:** [July 17, 2006, 10:41am UTC](https://www.ruby-forum.com/t/how-to-invoke-model-methods-in-controller-vice-versa/98647/4 "2006-07-17T10:41:57Z")

</div>

You’re probably trying to call an instance method. So first create a new  
Shortform object.

s = Shortform.new  
price=s.price

Joerg

Narayana Karthik wrote:

> hai  
> first of all thx to u for explaining  
> i did the same way like that ur qouted  
> even am calling the method in model  
> by doing  
> s=Shortform.price # shortform is the model class & price is the method  
> in it  
> but the error was arise error: undefine method price in shortform  
> am checked the spelling & am define the particular method also  
> but the error was arise  
> plz help me Mr.
> 
> Thx
> 
> Ben J. wrote:
> 
> > You shouldn’t be invoking any controllers methods from your models,  
> > but to invoke a method from a controller on a model you do it the  
> > same way you do in every other ruby class.
> > 
> > obj = ModelName.new
> > 
> > go from there.
> > 
> > Thank You,  
> > Ben J.  
> > E: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![narayana](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f6c823/32.png) [@narayana](https://www.ruby-forum.com/u/narayana)\
**Post date:** [July 17, 2006, 11:12am UTC](https://www.ruby-forum.com/t/how-to-invoke-model-methods-in-controller-vice-versa/98647/5 "2006-07-17T11:12:22Z")

</div>

Thank u Joerg D.  
thx very much

> You’re probably trying to call an instance method. So first create a  
> new  
> Shortform object.
> 
> s = Shortform.new  
> price=s.price
> 
> Joerg
> 
> Narayana Karthik wrote:
> 
> > hai  
> > first of all thx to u for explaining  
> > i did the same way like that ur qouted  
> > even am calling the method in model  
> > by doing  
> > s=Shortform.price # shortform is the model class & price is the method  
> > in it  
> > but the error was arise error: undefine method price in shortform  
> > am checked the spelling & am define the particular method also  
> > but the error was arise  
> > plz help me Mr.
> > 
> > Thx
> > 
> > Ben J. wrote:
> > 
> > > You shouldn’t be invoking any controllers methods from your models,  
> > > but to invoke a method from a controller on a model you do it the  
> > > same way you do in every other ruby class.
> > > 
> > > obj = ModelName.new
> > > 
> > > go from there.
> > > 
> > > Thank You,  
> > > Ben J.  
> > > E: removed\_email\_address@domain.invalid
