# Putting a controller into a gem?

**URL:** <https://www.ruby-forum.com/t/putting-a-controller-into-a-gem/136518>\
**Category:** Rails\
**Created:** [May 3, 2008, 12:19am UTC](https://www.ruby-forum.com/t/putting-a-controller-into-a-gem/136518 "2008-05-03T00:19:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [May 3, 2008, 12:19am UTC](https://www.ruby-forum.com/t/putting-a-controller-into-a-gem/136518/1 "2008-05-03T00:19:18Z")

</div>

If I put a controller class into a gem, and then require that gem in  
my application, will the controller then be available to handle  
requests?

I’m designing a controller that I think could be useful for more than  
one project, so I was thinking I would develop it separately and  
create a gem for my main project to use. However, I don’t know much  
about gems yet, so I’m not sure if this would work.  
–Paul

---

<div class="post-metadata">

**Author:** ![plambert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/9d8465/32.png) [@plambert](https://www.ruby-forum.com/u/plambert)\
**Post date:** [May 3, 2008, 12:33am UTC](https://www.ruby-forum.com/t/putting-a-controller-into-a-gem/136518/2 "2008-05-03T00:33:21Z")

</div>

On May 2, 11:18 pm, “Paul E. G. Lynch” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> If I put a controller class into a gem, and then require that gem in  
> my application, will the controller then be available to handle  
> requests?

Well it can be done from a plugin, you just need to add the folder  
containing your models to $LOAD\_PATH, Dependencies.load\_paths and  
config.controller\_paths (where config is the object in the initializer  
block in environment.rb). My controller wasn’t rendering any views  
(just json) but If you were you’d probably need to fiddle around with  
view paths. With any luck you’ll be able to massage this into working  
with a gem too.

Fred
