# Call model method out of the controller =\> undefined method

**URL:** <https://www.ruby-forum.com/t/call-model-method-out-of-the-controller-undefined-method/121064>\
**Category:** Rails\
**Created:** [November 23, 2007, 12:19pm UTC](https://www.ruby-forum.com/t/call-model-method-out-of-the-controller-undefined-method/121064 "2007-11-23T12:19:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![danmcb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@danmcb](https://www.ruby-forum.com/u/danmcb)\
**Post date:** [November 23, 2007, 12:19pm UTC](https://www.ruby-forum.com/t/call-model-method-out-of-the-controller-undefined-method/121064/1 "2007-11-23T12:19:50Z")

</div>

Hi,

I’m a newby and I fight with the Rails convention - i think so.  
I’ve done little tools and scripts in Ruby before.

I’ve successfully uploaded a textfile. And now i want to extract some  
filecontent to pass it into a database.

My Problem:  
I can not start a given method of a given Model (=\>  
Metadata.extract\_content(fileuri)). The error message ‘undefined method  
`extract\_content’ for Metadata:Class’ is raised. But the method is still  
there!?

My Controller Action:  
#########################################

def upload  
@schema\_file = params[:schema\_file]

```
@file = File.new(File.join("D:","testfile.txt"), "wb")
if @schema_file
  @file << @schema_file.read
end
@file.close

Metadata.extract_content(@file) # <- error causing line

render :action => 'load'

```

end

#########################################

My Model:  
#########################################

class Metadata \< ActiveRecord::Base

def extract\_content file  
# logic  
end

end

#########################################

Apart from this i’m not allowed to call any extern method out of the  
controller. (?)

- How can i call extern method?
- Are there any RoR conventions or constrains for this topic?

Thanks for helping.  
Daniel

---

<div class="post-metadata">

**Author:** ![danmcb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@danmcb](https://www.ruby-forum.com/u/danmcb)\
**Post date:** [November 23, 2007, 12:23pm UTC](https://www.ruby-forum.com/t/call-model-method-out-of-the-controller-undefined-method/121064/2 "2007-11-23T12:23:13Z")

</div>

use:

class Metadata …  
def self.extract\_content …

to define it on class level

your version would have to be called with an object:  
@thing = Metadata.new(…)  
@thing.extract\_content(@file)

---

<div class="post-metadata">

**Author:** ![danmcb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@danmcb](https://www.ruby-forum.com/u/danmcb)\
**Post date:** [November 23, 2007, 12:36pm UTC](https://www.ruby-forum.com/t/call-model-method-out-of-the-controller-undefined-method/121064/3 "2007-11-23T12:36:38Z")

</div>

Thanks. Problem solved.

---

<div class="post-metadata">

**Author:** ![danmcb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@danmcb](https://www.ruby-forum.com/u/danmcb)\
**Post date:** [December 4, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/call-model-method-out-of-the-controller-undefined-method/121064/4 "2007-12-04T17:04:09Z")

</div>

Dear reader,  
please have a look at our new database for students [www.spirofrog.de](http://www.spirofrog.de) –  
Start Your Global Career.

We want to help students from Germany and Europe to do an internship in  
foreign countries and international students to find suitable positions  
in  
German and European companies.

Additionally, we also place students in jobs for Young Professionals.  
This  
service is sponsored by companies = Students have free access  
Our customers include TVM Capital, European Investors Inc., Ebay, and  
many  
more.

We would also like to post job offers and the company profile from your  
company in our database.

Please do not hesitate to contact us and we will try to find you the  
suitable candidates or companies.

Best regards,  
Jessica from Spirofrog – Start Your Global Career

> > > Member of [http://www.bicc-net.de/](http://www.bicc-net.de/) \<\<\<

No virus found in this outgoing message.  
Checked by AVG Free Edition.  
Version: 7.5.503 / Virus Database: 269.16.13/1169 - Release Date:  
03.12.2007  
22:56
