# Extending controllers with actions from external files?

**URL:** <https://www.ruby-forum.com/t/extending-controllers-with-actions-from-external-files/88121>\
**Category:** Rails\
**Created:** [March 8, 2007, 11:12am UTC](https://www.ruby-forum.com/t/extending-controllers-with-actions-from-external-files/88121 "2007-03-08T11:12:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 8, 2007, 11:12am UTC](https://www.ruby-forum.com/t/extending-controllers-with-actions-from-external-files/88121/1 "2007-03-08T11:12:26Z")

</div>

Hey 🙂

I have some auto\_complete\_for\_blah\_blah actions that are used in  
different controllers. In the spirit of DRY, I’d like to separate  
these actions in unique files which I then load into the controllers  
that use them.

Okay, so the way I can do it now is for instance  
myapp  
± lib  
± auto\_complete\_for  
± user\_printed\_name.rb

And then, I can  
require ‘auto\_complete\_for/user\_printed\_name’

in the controllers that use this auto\_completer.

However, even though the method is available to the controller, I  
still get “no action responded to  
‘auto\_complete\_for\_user\_printed\_name’” when I call the action. That  
is, it’s available as a local method to the controller, but I’d really  
like for it to appear as an action, so that I don’t have to create a  
proxy, like,

def auto\_complete\_for\_user\_printed\_name  
shared\_auto\_complete\_for\_user\_printed\_name  
end

How would I do that?

Thanks 🙂

Daniel

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 8, 2007, 11:51am UTC](https://www.ruby-forum.com/t/extending-controllers-with-actions-from-external-files/88121/2 "2007-03-08T11:51:31Z")

</div>

Daniel Smedegaard B. wrote the following on 08.03.2007 11:11 :

> ```
> +- auto_complete_for
> +- user_printed_name.rb
> 
> ```
> 
> And then, I can  
> require ‘auto\_complete\_for/user\_printed\_name’
> 
> in the controllers that use this auto\_completer.

From memory, you should:  
include AutoCompleteFor::UserPrintedName

assuming this the module name defined in  
lib/auto\_complete\_for/user\_printed\_name.rb

You probably don’t need the require if your module naming matches your  
directory structure like in the example above (Rails figures the needed  
require for itself).

Lionel

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [March 8, 2007, 12:19pm UTC](https://www.ruby-forum.com/t/extending-controllers-with-actions-from-external-files/88121/3 "2007-03-08T12:19:34Z")

</div>

On Mar 8, 11:50 am, Lionel B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> 

Close! Following your advice and a little fiddling, I found that with,

lib/auto\_complete\_for.rb:  
module AutoCompleteFor  
module UserPrintedName  
def auto\_complete\_for\_user\_printed\_name  
// implementation  
end  
end  
end

I can use the syntax you describe,

include AutoCompleteFor::UserPrintedName

and have the actions implemented!

Thank you very much! 😃

Daniel 🙂
