# Using a Rails plugin in Radiant extensions

**URL:** <https://www.ruby-forum.com/t/using-a-rails-plugin-in-radiant-extensions/105965>\
**Category:** Radiant CMS\
**Created:** [June 5, 2007, 1:16am UTC](https://www.ruby-forum.com/t/using-a-rails-plugin-in-radiant-extensions/105965 "2007-06-05T01:16:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andrew\_OSBrien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@Andrew\_OSBrien](https://www.ruby-forum.com/u/Andrew_OSBrien)\
**Post date:** [June 5, 2007, 1:16am UTC](https://www.ruby-forum.com/t/using-a-rails-plugin-in-radiant-extensions/105965/1 "2007-06-05T01:16:18Z")

</div>

I’m trying to make a radiant friendly wrapping around the  
Authorization plugin  
([http://www.writertopia.com/developers/authorization](http://www.writertopia.com/developers/authorization)) and I was  
wondering: what’s the best way to use a Rails plugin inside of a  
Radiant extension?

I noticed there’s a vendor/plugin directory in the standard project  
layout, but it doesn’t seem to be in the include path. I also tried  
adding a vendor/plugins directory to the extension (since it would be  
kind of nice to bundle them together anyway), but that didn’t quite  
worked either.

Any suggestions?

Thanks,  
Andrew

Oh, and in case you’re wondering, I’m trying to add a controller to  
allow role creation and assignment, as well as compatibility with  
Radiant’s existing authorization system.

---

<div class="post-metadata">

**Author:** ![Andrew\_OSBrien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@Andrew\_OSBrien](https://www.ruby-forum.com/u/Andrew_OSBrien)\
**Post date:** [June 5, 2007, 1:23am UTC](https://www.ruby-forum.com/t/using-a-rails-plugin-in-radiant-extensions/105965/2 "2007-06-05T01:23:19Z")

</div>

I included attachment\_fu in my page\_attachments extension. It was kind  
of tricky, but here’s the basic strategy:

1. Import the plugin’s lib/ directory into the lib/ directory of your  
extension via svn:externals, piston, or an export.
2. Copy the contents of the init.rb file into the ‘activate’ method of  
your extension.

You may have to fiddle with things to make sure they work right. Here’s  
another potential strategy, YMMV:  
(in ‘activate’)

1. Wherever you stored it, push the plugin’s lib/ directory into the  
load path.
2. Load or require the plugin’s init.rb.

In either strategy, the plugin should probably be dealt with first (i.e.  
placed first in the activate method) if your extension depends on it  
during its activation.

Sean

---

<div class="post-metadata">

**Author:** ![Andrew\_OSBrien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@Andrew\_OSBrien](https://www.ruby-forum.com/u/Andrew_OSBrien)\
**Post date:** [June 5, 2007, 6:00pm UTC](https://www.ruby-forum.com/t/using-a-rails-plugin-in-radiant-extensions/105965/3 "2007-06-05T18:00:57Z")

</div>

Ah yes, the activation method – that’s probably a better place than  
the top of the file…

My tests are passing, so things seem to be working better. One  
problem I’m having though is that it seems to be initializing  
constants twice. E.g.:

/Users/aobrien/WorkingDirectory/tgi\_cms/vendor/extensions/subscription\_manager/vendor/plugins/authorization/lib/publishare/parser.rb:4:  
warning: already initialized constant VALID\_PREPOSITIONS

It does this for all of the constants in the plugin. They’re  
definitely specific to the Authorization plugin and not initialized  
beforehand (I’ve tried inserting “raise” commands if the constant is  
already defined) and the file is only required once (according to the  
“puts” commands I put in).

They’re just warnings, so I can probably live with them, but if this  
rings any bells with anyone, I’d be glad to hear.

Thanks,  
Andrew

---

<div class="post-metadata">

**Author:** ![Andrew\_OSBrien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@Andrew\_OSBrien](https://www.ruby-forum.com/u/Andrew_OSBrien)\
**Post date:** [June 5, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/using-a-rails-plugin-in-radiant-extensions/105965/4 "2007-06-05T18:19:59Z")

</div>

You might try wrapping your plugin initialization code in a block like  
so:

unless defined?(VALID\_PREPOSITIONS)

# init.rb contents goes here

end

Any constant defined in the plugin should do, including any class.

Sean

---

<div class="post-metadata">

**Author:** ![Andrew\_OSBrien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d6d6ee/32.png) [@Andrew\_OSBrien](https://www.ruby-forum.com/u/Andrew_OSBrien)\
**Post date:** [June 5, 2007, 7:14pm UTC](https://www.ruby-forum.com/t/using-a-rails-plugin-in-radiant-extensions/105965/5 "2007-06-05T19:14:21Z")

</div>

Actually – I take that back. Stupid mistake on my part. I had the  
artifact of another extension that had a local copy of the plugin in  
it’s directory. That would explain why it only looked like the files  
were being required once - that other extension was requiring exact  
copies of the same files.

My bad and thanks for the help,  
Andrew
