开发者

ActiveResource NameError calling a WCF Service

Lately I've been working on validating an architectural design idea using Rails ActiveResource as a client and a WCF restful service as a server. I have the WCF service running on Windows Vista in a bootcamp partition on a Macintosh hosted in VMWare Fusion (self hosted mode). When I call the service from the Mac in a browser, I do indeed get the correct xml response from the virtual server. This is done by getting the ip address from the Vista server and using it in the uri.

http://168.192.243.128/WCFTestService/ContextService.svc/dtree/14

This service returns an instance of a class called "Context" with three DataMember attributes exposed (id = 14). I want to use the class name "DTree" in the Rails (2.3.2) client so I define the following:

class DTree < ActiveResource::Base

 self.site = 'http://168.192.243.128/WCFTestService/ContextService.svc/'

end

The issue that I'm experiencing may have little to do with this setup though.

When I startup the consol开发者_如何学Goe at the test project root in Rails and type the following:

DTree.find(14)

I get: NameError: uninitialized constant DTree (...)

The fine art of googling doesn't seem to turn up anything of real use, which sometimes tells me that my issue is a no-brainer and why would someone post an answer to this type of issue. From all I can tell and from other examples my active resource class should be at least recognized in the rails console with no more than defining the class. Another error would be fine.


I thought I would answer my own question because it turned out to be a no brainer and I hate arriving at questions online with no answer.

This was basically caused by the fact that active resource classes are not created using the script/generate command which ensures the correct name and location of the file.

My class name is DTree and I created a file named dtree.rb in the /models directory. It should have been named d_tree.rb and located in the /lib directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜