# Instanciating a class

**URL:** <https://www.ruby-forum.com/t/instanciating-a-class/69649>\
**Category:** Rails\
**Created:** [September 22, 2006, 5:36pm UTC](https://www.ruby-forum.com/t/instanciating-a-class/69649 "2006-09-22T17:36:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![btreb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/22d042/32.png) [@btreb](https://www.ruby-forum.com/u/btreb)\
**Post date:** [September 22, 2006, 5:36pm UTC](https://www.ruby-forum.com/t/instanciating-a-class/69649/1 "2006-09-22T17:36:19Z")

</div>

Hi i had a quick question.  
if i have a class inside a folder say controllers \>\> plugins \>\>  
test\_plugin\_conroller.rb, how can i get a reference to this class and  
call .new on it to create an instance of it. Iv tried doing this:

@s = Kernel.const\_get(“TestPluginController”)  
@sc = @st.new

but it sais uninitialized constant TestPluginController, does anyone  
have a solution? thank you for the help.

Brandon

---

<div class="post-metadata">

**Author:** ![btreb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/22d042/32.png) [@btreb](https://www.ruby-forum.com/u/btreb)\
**Post date:** [September 22, 2006, 6:09pm UTC](https://www.ruby-forum.com/t/instanciating-a-class/69649/2 "2006-09-22T18:09:47Z")

</div>

Why would you have a model inside of the controllers folder?

I believe you just need a require statement to load the model file if  
it’s outside the normal models location.

Jason

---

<div class="post-metadata">

**Author:** ![btreb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/22d042/32.png) [@btreb](https://www.ruby-forum.com/u/btreb)\
**Post date:** [September 22, 2006, 6:11pm UTC](https://www.ruby-forum.com/t/instanciating-a-class/69649/3 "2006-09-22T18:11:47Z")

</div>

test\_plugin\_controller.rb _does_ contain

Class TestPluginController  
stufff  
end

, doesn’t it?

Also: check from the console that that class has actually been loaded  
by your Rails app. If not, that’s probably the issue.

Otherwise, Kernel.const\_get(“TestPluginController”).new _should_ work.

---

<div class="post-metadata">

**Author:** ![btreb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/22d042/32.png) [@btreb](https://www.ruby-forum.com/u/btreb)\
**Post date:** [September 22, 2006, 6:22pm UTC](https://www.ruby-forum.com/t/instanciating-a-class/69649/4 "2006-09-22T18:22:10Z")

</div>

Ok so i moved the plugin to models \>\> plugins \>\> test.rb

test.rb contains

class Test \< ActiveRecord::Base  
end

so i did  
require(“models/plugins/test.rb”)  
@s = Kernel.const\_get(“Test”)  
@sc = @st.new

and it said

Test is not a class

any other ideas? thank you so much for your help
