Soap4r and Rails
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: ruby on rails, soap, lyris
James @ April 18, 2007
Would this problem not be the case if Rails were loaded from gems rather than from the vendors directory?
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.
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.
I’m trying your fix, but I still get the same error, when running inside rails. Standalone works fine. Any guesses?
Thanks!
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.
[…] Soap4r and Rails | Blue Jazz Consulting - Austin-based Ruby on Rails, Architecture, and Technical Le… (tags: soap rails) […]