# Adding actions/methods to a controller via a plugin

**URL:** <https://www.ruby-forum.com/t/adding-actions-methods-to-a-controller-via-a-plugin/88735>\
**Category:** Rails\
**Created:** [March 13, 2007, 10:03pm UTC](https://www.ruby-forum.com/t/adding-actions-methods-to-a-controller-via-a-plugin/88735 "2007-03-13T22:03:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pixellover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pixellover](https://www.ruby-forum.com/u/pixellover)\
**Post date:** [March 13, 2007, 10:03pm UTC](https://www.ruby-forum.com/t/adding-actions-methods-to-a-controller-via-a-plugin/88735/1 "2007-03-13T22:03:50Z")

</div>

Hi,

I would like to develop a plugin, that if enabled in a controller,  
extends the  
controller with some basic methods (actions).

Here’s what I’ve done so far:  
In init.rb:

require ‘my\_scaffold’  
ActionController::Base.send :include, MyScaffold

in lib/my\_scaffold.rb:

module MyScaffold  
def foo  
render :text =\> “Hello World”  
end  
end

But everytime I try to access this new action “foo” I get an “Unknown  
Action”  
error from rails.

What am I missing?

Timo

---

<div class="post-metadata">

**Author:** ![pixellover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pixellover](https://www.ruby-forum.com/u/pixellover)\
**Post date:** [March 14, 2007, 9:44am UTC](https://www.ruby-forum.com/t/adding-actions-methods-to-a-controller-via-a-plugin/88735/2 "2007-03-14T09:44:54Z")

</div>

Hi,

after some more tests the problem seems to be with defining methods as  
public:

> in lib/my\_scaffold.rb:
> 
> module MyScaffold  
> def foo  
> render :text =\> “Hello World”  
> end  
> end

Calling foo from another methode, i.e. “index” the text “Hello World” is  
rendered:

class MyController \< ApplicationController  
def index  
foo  
end  
end

Seems like the added methode “foo” isn’t a public methode. So, how do I  
define  
the foo-methode as public?

Regards,  
Timo

---

<div class="post-metadata">

**Author:** ![pixellover](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ee59a6/32.png) [@pixellover](https://www.ruby-forum.com/u/pixellover)\
**Post date:** [April 1, 2007, 10:20pm UTC](https://www.ruby-forum.com/t/adding-actions-methods-to-a-controller-via-a-plugin/88735/3 "2007-04-01T22:20:57Z")

</div>

Hallo Timo

Did you found any other solution to this issue?

I just want to create a controller class into my plugin,  
in order to call it directly from browser. But I don’t get it running.

Thanks.
