# Developing plugins

**URL:** <https://discuss.rubyonrails.org/t/developing-plugins/51020>\
**Category:** rubyonrails-talk\
**Created:** [April 19, 2010, 3:40pm UTC](https://discuss.rubyonrails.org/t/developing-plugins/51020 "2010-04-19T15:40:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nicholas\_Wieland](https://avatars.discourse-cdn.com/v4/letter/n/e8c25b/32.png) [@Nicholas\_Wieland](https://discuss.rubyonrails.org/u/Nicholas_Wieland)\
**Post date:** [April 19, 2010, 3:40pm UTC](https://discuss.rubyonrails.org/t/developing-plugins/51020/1 "2010-04-19T15:40:20Z")

</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 &nbsp;&nbsp;#some stuff end

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

and in charon/class\_methods

module Charon &nbsp;&nbsp; &nbsp;&nbsp;module CharonClassMethods

&nbsp;&nbsp;&nbsp;&nbsp;def self.included base &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;base.send :extend, Charon::CharonClassMethods::ClassMethods &nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;module ClassMethods

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;def authentication\_url &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# implementation &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;&nbsp;&nbsp;end

&nbsp;&nbsp;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, &nbsp;&nbsp;ngw

---

<div class="post-metadata">

**Author:** ![Frederick\_Cheung](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/frederick_cheung/32/3901_2.png) [@Frederick\_Cheung](https://discuss.rubyonrails.org/u/Frederick_Cheung)\
**Post date:** [April 19, 2010, 11:15pm UTC](https://discuss.rubyonrails.org/t/developing-plugins/51020/2 "2010-04-19T23:15:52Z")

</div>

> 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
