June 11, 2006

Posted by John

Tagged plugins

Older: Hash Goodness

Newer: RJS Class Proxies

Using App Guts in Your Plugins

You know how Rails Engines allow you to reuse controllers, helpers, models and views? Well, you can do it with plugins too. ezmobius over at Caboo.se just posted how. Put these four lines in the plugins init.rb …

config.controller_paths << File.join(directory, 'app', 
  'controllers')
$LOAD_PATH << File.join(directory, 'app', 'controllers')
$LOAD_PATH << File.join(directory, 'app', 'models')
$LOAD_PATH << File.join(directory, 'app', 'helpers')

Now you can add an app/ directory in the root of your plugin with controllers, helpers, models and views. Sweet!

Also, note that you need to add something like the following in all of the plugins controllers …

FooController.template_root = File.join(File.dirname(__FILE__), '..', 'views')

I have been using Rails for websites more than for applications as most of the sites I create use administration areas. Sites often times have things in common such as news, events, contact form, etc. This tip will come in really handy. I could also see it used for an authentication system as mine often function the same.

0 Comments

Thoughts? Do Tell...


textile enabled, preview above, please be nice
use <pre><code class="ruby"></code></pre> for code blocks

About

Authored by John Nunemaker (Noo-neh-maker), a web developer and programmer who has fallen deeply in love with Ruby. More about John.

Syndication

Feed IconRailsTips Articles - An assortment of howto's and thoughts on Ruby and Rails.

Feed IconRails Quick Tips - Ruby and Rails related links.