Lib loading/requiring for an extension

Hi all, quick question.

I’ve used this hack effectively in a normal rails app: http://
www.pluitsolutions.com/2007/03/20/custom-in_place_edit-with-validation/

It requires a file in the lib/ directory and a ‘require’ in
environment.rb

The former I can do, but in the extension’s lib directory. The latter
I can’t (as an extension). I followed this post http://
lists.radiantcms.org/pipermail/radiant/2007-January/003160.html but
still no joy.

Any ideas? Is this do-able?

Kind regards,
-Karl

On Apr 3, 2007, at 2:41 PM, Karl Doody wrote:

It requires a file in the lib/ directory and a ‘require’ in
environment.rb

The former I can do, but in the extension’s lib directory. The latter
I can’t (as an extension). I followed this post http://
lists.radiantcms.org/pipermail/radiant/2007-January/003160.html but
still no joy.

Any ideas? Is this do-able?

So, as I understand it, you need to require a file in your
extension’s lib directory? Any reason you can’t do this in your
extension’s activate method?

adam williams

Okay, I gave that a go but WebBrick fails to start (with a rather
cryptic error):

./script/server -e production
=> Booting WEBrick…
/opt/local/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/
webrick.rb:11: warning: already initialized constant OPTIONS
/opt/local/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/rails/
activerecord/lib/active_record/vendor/mysql.rb:1127:in write': Lost connection to MySQL server during query (Mysql::Error) from /opt/local/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/ rails/activerecord/lib/active_record/vendor/mysql.rb:1177:infinalizer’
from /opt/local/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/
rails/actionpack/lib/action_controller/routing.rb:642:in call' from /opt/local/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/ rails/actionpack/lib/action_controller/routing.rb:642:ininitialize’
from /opt/local/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/
rails/actionpack/lib/action_controller/routing.rb:845:in new' from /opt/local/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/ rails/actionpack/lib/action_controller/routing.rb:845:insegment_for’
from /opt/local/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/
rails/actionpack/lib/action_controller/routing.rb:822:in
segments_for_route_path' from /opt/local/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/ rails/actionpack/lib/action_controller/routing.rb:950:inbuild’
from /opt/local/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/
rails/actionpack/lib/action_controller/routing.rb:1172:in add_route' ... 39 levels... from /opt/local/lib/ruby/gems/1.8/gems/radiant-0.6.0/vendor/ rails/railties/lib/commands/server.rb:39 from /opt/local/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:ingem_original_require’
from /opt/local/lib/ruby/site_ruby/1.8/rubygems/
custom_require.rb:27:in `require’
from ./script/server:3

…and the offending code:

def activate
admin.tabs.add “Testimonials”, “/admin/testimonials”, :after =>
“Layouts”, :visibility => [:all]
require “custom_in_place_editing”
end

-Karl