# Developing plugins

**URL:** <https://www.ruby-forum.com/t/developing-plugins/187197>\
**Category:** Rails\
**Created:** [April 19, 2010, 5:42pm UTC](https://www.ruby-forum.com/t/developing-plugins/187197 "2010-04-19T17:42:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [April 19, 2010, 5:42pm UTC](https://www.ruby-forum.com/t/developing-plugins/187197/1 "2010-04-19T17:42:14Z")

</div>

Hi \*,  
I’m trying to develop a plugin, but I’m having some problems integrating  
it in Rails.

The first problem is when I need to load the environment: I would like  
the plugin to be installable in the classic way (under /vendor) and as a  
gem. Right now I’m using something like

require File.join( File.dirname( **FILE** ), ‘…’, ‘…’, ‘…’, ‘…’,  
‘config’, ‘environment’ )

but of course I don’t think it will work as a gem. How can I require the  
env to have it work in both ways ?

The other problem I’m facing is when I try to have the plugin to include  
itself inside ActionController (an example can be login\_required of  
restful authentication).  
This is what I’m trying to do:

$:.unshift File.expand\_path( File.dirname( **FILE** ) )  
require ‘charon/class\_methods’

module Charon  
#some stuff  
end

ActionController::Base.send :include, Charon::CharonClassMethods

and in charon/class\_methods

module Charon

module CharonClassMethods

```
def self.included base
  base.send :extend, Charon::CharonClassMethods::ClassMethods
end

module ClassMethods

  def authentication_url
    # implementation
  end

end

```

end

end

What I don’t understand where I should include the main application, how  
to load rails and when (I can require ActionController in the first file  
but it doesn’t feel right …) and what to put inside hte various  
initialization files.  
If someone knows of a plugin with specs that I can copy I would be very  
glad. It’s not that I don’t find them, but every plugin I find does  
things in a different way, so it’s not entirely clear which way is the  
best one.

TIA,  
ngw

---

<div class="post-metadata">

**Author:** ![Nicholas\_W](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/f17d59/32.png) [@Nicholas\_W](https://www.ruby-forum.com/u/Nicholas_W)\
**Post date:** [April 20, 2010, 1:17am UTC](https://www.ruby-forum.com/t/developing-plugins/187197/2 "2010-04-20T01:17:08Z")

</div>

On Apr 19, 4:40 pm, Nicholas W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> What I don’t understand where I should include the main application, how to load rails and when (I can require ActionController in the first file but it doesn’t feel right …) and what to put inside hte various initialization files.  
> If someone knows of a plugin with specs that I can copy I would be very glad. It’s not that I don’t find them, but every plugin I find does things in a different way, so it’s not entirely clear which way is the best one.

Well the rails framework (and constituent parts) will already have  
been loaded at the point your init.rb is run. requiring config/  
environment again at that point probably doesn’t do anything at all.  
For a gem plugin if my memory is correct you’ll want to ensure rails/  
init.rb exists (and do your rails specific setup in there).

Fred
