We can take your startup from idea to revenue.   Find out more ยป


Soap4r and Rails

Ruby

I recently wrapped up a short project bridging a Rails application to the Lyris ListManager API. One of things I had to do was use soap4r to support client calls over SOAP to the ListManager services. I the midst of the development, I encountered the following problem:

NameError: uninitialized constant SOAP::Mapping::EncodedRegistry

While I found some support for the issue in a few places, the end result was that i needed to modify boot.rb for my Rails app to load the soap4r gem earlier in the boot process (sounds like a Java CLASSPATH issue, eh?). The problem is that the project installs Rails using a svn external link inside the vendor directory. The suggested fix didn’t quite cover what I needed though the spirit of fix was there. Here is what I changed in boot.rb to make it work:

From:

if File.directory?(”#{RAILS_ROOT}/vendor/rails”)
  require “#{RAILS_ROOT}/vendor/rails/railties/lib/initializer”

To:

if File.directory?(”#{RAILS_ROOT}/vendor/rails”)
# Making a change here to force the soap4r gem to preload before the SOAP version packaged with Ruby/Rails
  require ‘rubygems’
  begin
    require_gem ’soap4r’
  rescue => e
    raise “The gem soap4r was not found. Please perform a ‘gem install soap4r’.”
  end
# Now, back to our regularly scheduled program, already in progress…
require “#{RAILS_ROOT}/vendor/rails/railties/lib/initializer”

I hope this helps others that struggle over the same problem and are using the same project structure.

Technorati Tags: , ,

James @ April 18, 2007

6 Comments

  1. Ryan May 2, 2007 @ 12:17 pm

    Would this problem not be the case if Rails were loaded from gems rather than from the vendors directory?

  2. James May 2, 2007 @ 4:52 pm

    Ryan,

    No, it doesn’t matter which way you choose to launch Rails - via gems or under a vendor directory - the issue still remains.

    My post identifies the fact that the fix commonly found via Google only works if you are using Rails via gems. The fix I documented above solves the problem if Rails is loaded under the vendor directory - a fact that I found after spending some time wondering why the original fix didn’t work.

  3. Ryan May 7, 2007 @ 10:43 am

    I wonder if it would be possible to load soap4r from a plugin instead of a gem. Thought that might not solve the load order problem.

  4. Bob May 24, 2007 @ 12:50 pm

    I’m trying your fix, but I still get the same error, when running inside rails. Standalone works fine. Any guesses?

    Thanks!

  5. James May 25, 2007 @ 6:29 am

    Bob,

    Without more information it may be hard to determine the problem. Just make sure that you have read all of the links that I referenced in my post, and be sure that you apply my fix only if you are running rails from under vendor, rather than as a gem.

  6. RAILroading » Blog Archive » links for 2008-02-13 February 12, 2008 @ 11:08 pm

    […] Soap4r and Rails | Blue Jazz Consulting - Austin-based Ruby on Rails, Architecture, and Technical Le… (tags: soap rails) […]

Leave a comment


Feed Contact Us