# Help on building a plugin

**URL:** <https://www.ruby-forum.com/t/help-on-building-a-plugin/85442>\
**Category:** Rails\
**Created:** [February 13, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/help-on-building-a-plugin/85442 "2007-02-13T16:27:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 13, 2007, 4:27pm UTC](https://www.ruby-forum.com/t/help-on-building-a-plugin/85442/1 "2007-02-13T16:27:12Z")

</div>

Hi,

I’ve developed some code that allows you to use s3 as a cache store  
(ie store your cache fragments at s3 instead of your web server).

It works great when I have the code in my lib/ folder.

Now I want to package it as a plugin. i’m stuck.

My plugin directory is structured:

- s3cache  
– init.rb  
– lib/  
----- s3\_cache.rb  
----- s3.rb

My init.rb file is this:  
require ‘s3\_cache’

My lib/s3\_cache file begins with:

require ‘S3’

class S3Cache \<  
ActionController::Caching::Fragments::UnthreadedFileStore  
def initialize(bucket, cache\_directory)  
@aws\_access\_key = ‘YOURAWSACCESSKEY’ # your AWS ACCESS  
KEY  
@aws\_secret\_access\_key = ‘YOURAWSSECRETKEY’ # your SECRET  
@bucket = bucket

* * *

In my config/environments/development.rb file I add the following  
line:  
config.action\_controller.fragment\_cache\_store =  
S3Cache.new(“quizical”, “cache”)

* * *

The problem is now when I start my server, I get the following error

/usr/local/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/  
active\_support/dependencies.rb:123:in `const\_missing’: uninitialized  
constant S3Cache (NameError)

* * *

Everything works fine if I put s3\_cache.rb and s3.rb in my lib/  
folder. But I seem to be missing something in init.rb of my plugin or  
have something else structured wrong.

any ideas?

Steve

> **[Niblets....Simple. Less.](https://niblets.wordpress.com/)**
>
> Just another WordPress.com weblog

ps. check it out at [www.quizical.net](http://www.quizical.net) and see if you can tell speed-  
wise that I’m storing cache fragments at s3. I’m also serving up all  
of my public directory from s3 too - essentially using it as my asset  
server.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 14, 2007, 2:28am UTC](https://www.ruby-forum.com/t/help-on-building-a-plugin/85442/2 "2007-02-14T02:28:20Z")

</div>

On 2/13/07, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The problem is now when I start my server, I get the following error

Plugins are loaded _after_ the environment is loaded. Subscribe to  
Rick O.'s blog and read these entries:  
[http://weblog.techno-weenie.net/2007/1/24/understanding-the-rails-initialization-process](http://weblog.techno-weenie.net/2007/1/24/understanding-the-rails-initialization-process)

then

[http://weblog.techno-weenie.net/2007/1/25/understanding-the-rails-initialization-process-part-2](http://weblog.techno-weenie.net/2007/1/25/understanding-the-rails-initialization-process-part-2)

Shortcut: in config/environments/development.rb put:

config.after\_initialize do  
config.action\_controller.fragment\_cache\_store =  
S3Cache.new(“quizical”, “cache”)  
end

–  
Chris W.

> **[err.the\_blog](http://errtheblog.com)**
>
> Err the Blog: Ruby and Rails from the front.

---

<div class="post-metadata">

**Author:** ![unknown](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/4bbf92/32.png) [@unknown](https://www.ruby-forum.com/u/unknown)\
**Post date:** [February 14, 2007, 5:55am UTC](https://www.ruby-forum.com/t/help-on-building-a-plugin/85442/3 "2007-02-14T05:55:36Z")

</div>

Doh! Of course. Thanks Chris. That was what I needed.
