# Class works on Ruby, does not work on Rails controller

**URL:** <https://www.ruby-forum.com/t/class-works-on-ruby-does-not-work-on-rails-controller/117578>\
**Category:** Rails\
**Created:** [October 18, 2007, 7:52am UTC](https://www.ruby-forum.com/t/class-works-on-ruby-does-not-work-on-rails-controller/117578 "2007-10-18T07:52:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ace](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@ace](https://www.ruby-forum.com/u/ace)\
**Post date:** [October 18, 2007, 7:52am UTC](https://www.ruby-forum.com/t/class-works-on-ruby-does-not-work-on-rails-controller/117578/1 "2007-10-18T07:52:10Z")

</div>

Dear All,

I have written a ruby class which uses the flickr webservice. When I  
wrote a “command line” sript using that class the I get a proper  
response (through res\_message). But when I use the class in a  
controller I get nil as the response

any help will be highly appreciated.

thanks.

## J

class is like this.

class FlickrClient  
def initialize(key)  
@key = key  
end

```
def query(text)
   payload = compile_query(text)

   @client = WSMyClient.new(Hash[:to => "http://api.flickr.com/

```

services/soap"])  
res\_message = @client.request(payload)

```
   return "Res Message : " << res_message.to_s
rescue => exception
   return "Exception : #{exception}"

 end

```

private  
def compile\_query(text)  
payload = \<\<XML  
\<x:FlickrRequest xmlns:x=“urn:flickr”\>  
flickr.photos.search  
\<api\_key\>#{@key}\</api\_key\>  
#{text}  
\</x:FlickrRequest\>  
XML  
return payload  
end

end

---

<div class="post-metadata">

**Author:** ![ace](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@ace](https://www.ruby-forum.com/u/ace)\
**Post date:** [October 18, 2007, 3:12pm UTC](https://www.ruby-forum.com/t/class-works-on-ruby-does-not-work-on-rails-controller/117578/2 "2007-10-18T15:12:53Z")

</div>

This may not directly answer your question, but take a look at the  
following link on NetBeans site. Amongst other links, it has one that  
demonstrates how to integrate flickr in Ruby on Rails. Most of it  
should apply to what you are trying to do.  
[http://www.netbeans.org/kb/60/ruby/](http://www.netbeans.org/kb/60/ruby/)’  
HTH.

---

<div class="post-metadata">

**Author:** ![ace](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/848f3c/32.png) [@ace](https://www.ruby-forum.com/u/ace)\
**Post date:** [October 18, 2007, 3:26pm UTC](https://www.ruby-forum.com/t/class-works-on-ruby-does-not-work-on-rails-controller/117578/3 "2007-10-18T15:26:57Z")

</div>

thanks.

I have tested the same (my) code with Webrick it works fine. With  
apache I am not getting the result as expected. It seems like the  
function does not wait until the result is recieved, moving to next  
line and execute it.

For the same Webrick gives a result to res\_message. Apache just return  
nil. please note that I am using a web service engine using c called  
through WSMyClient.

Does anybody have a clue?

```
  @client = WSMyClient.new(Hash[:to => "http://api.flickr.com/

```

services/soap"])  
res\_message = @client.request(payload)

regards,

J
