# Passing data from controller to rjs and then to partial

**URL:** <https://www.ruby-forum.com/t/passing-data-from-controller-to-rjs-and-then-to-partial/94362>\
**Category:** Rails\
**Created:** [May 2, 2006, 6:41am UTC](https://www.ruby-forum.com/t/passing-data-from-controller-to-rjs-and-then-to-partial/94362 "2006-05-02T06:41:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 2, 2006, 6:41am UTC](https://www.ruby-forum.com/t/passing-data-from-controller-to-rjs-and-then-to-partial/94362/1 "2006-05-02T06:41:35Z")

</div>

Hello Experts,

I am fetching data in my controller from a web service

def search  
response = @@api.DoSearch()  
end

and in my .rjs template, I am doing

page.replace\_html ‘fields\_chooser’, :partial =\> ‘fields\_chooser’  
,:locals =\>{:response =\> response}  
page.visual\_effect(:Appear, ‘fields\_chooser’)

and in \_fields\_chooser.rhtml, I want to use response. But I can’t see  
response in my .rhtml file.

what am I missing here? how do I pass data “response” from controller to  
the .rhtml file or should I be doing this in a different way?

Thanks guys for any help.

PS

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 2, 2006, 7:39am UTC](https://www.ruby-forum.com/t/passing-data-from-controller-to-rjs-and-then-to-partial/94362/2 "2006-05-02T07:39:14Z")

</div>

Did you mean @response instead of “response”?

Pradeep S. wrote:

> Hello Experts,
> 
> I am fetching data in my controller from a web service
> 
> def search  
> response = @@api.DoSearch()  
> end

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 2, 2006, 8:05am UTC](https://www.ruby-forum.com/t/passing-data-from-controller-to-rjs-and-then-to-partial/94362/3 "2006-05-02T08:05:36Z")

</div>

Hi,

I am actually using response.

strangely, If I do @response = @@api.DoSearch()

I get this error:

undefined method `body=’ for #Array:0x36accd0

Stack trace below:

however, if I just use response, I can see the response fine in logger,  
but I am not able to pass the response to the rjs template.

I am a NewB, so apologize if am not very clear.

Your help is greatly appreciated.

thanks,

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action\_controller/base.rb:746:in  
`erase_render_results' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:764:in`erase\_results’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action\_controller/rescue.rb:28:in  
`rescue_action' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/rescue.rb:108:in`perform\_action’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action\_controller/base.rb:379:in  
`send' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/base.rb:379:in`process\_without\_filters’  
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action\_controller/filters.rb:364:in  
`process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-1.12.0/lib/action_controller/session_management.rb:117:in`process’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/dispatcher.rb:38:in  
`dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:115:in`handle\_dispatch’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick\_server.rb:81:in  
`service' c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in`service’  
c:/ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' c:/ruby/lib/ruby/1.8/webrick/server.rb:155:in`start\_thread’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:144:in`start\_thread’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:94:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in`each’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:89:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in`start’  
c:/ruby/lib/ruby/1.8/webrick/server.rb:79:in `start' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/webrick_server.rb:67:in`dispatch’  
c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/servers/webrick.rb:59  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require__' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in`require’  
c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active\_support/dependencies.rb:136:in  
`require' c:/ruby/lib/ruby/gems/1.8/gems/rails-1.1.0/lib/commands/server.rb:30 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in`require\_\_’  
c:/ruby/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:21:in  
`require' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-1.3.0/lib/active_support/dependencies.rb:136:in`require’ script/server:3

Steve R. wrote:

> Did you mean @response instead of “response”?
> 
> Pradeep S. wrote:
> 
> > Hello Experts,
> > 
> > I am fetching data in my controller from a web service
> > 
> > def search  
> > response = @@api.DoSearch()  
> > end

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 2, 2006, 12:23pm UTC](https://www.ruby-forum.com/t/passing-data-from-controller-to-rjs-and-then-to-partial/94362/4 "2006-05-02T12:23:55Z")

</div>

Pradeep S. wrote:

> Hello Experts,
> 
> I am fetching data in my controller from a web service
> 
> def search  
> response = @@api.DoSearch()  
> end
> 
> and in my .rjs template, I am doing
> 
> page.replace\_html ‘fields\_chooser’, :partial =\> ‘fields\_chooser’  
> ,:locals =\>{:response =\> response}  
> page.visual\_effect(:Appear, ‘fields\_chooser’)

I haven’t been able to get the :locals parameter to work in an RJS call  
either, so what I’ve done in cases like this is to use an instance  
variable. @response is a reserved attribute so you might try a  
different variable name in such a case.

Jeff

---

<div class="post-metadata">

**Author:** ![psethi2000](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b3f665/32.png) [@psethi2000](https://www.ruby-forum.com/u/psethi2000)\
**Post date:** [May 3, 2006, 6:59pm UTC](https://www.ruby-forum.com/t/passing-data-from-controller-to-rjs-and-then-to-partial/94362/5 "2006-05-03T18:59:13Z")

</div>

The response variable that you have set

response = @@api.DoSearch()

is only local scope. When you enter your rjs, it has gone out of scope.

Use  
@response = @@api.DoSearch()

and in the rjs  
page.replace\_html ‘fields\_chooser’, :partial =\> ‘fields\_chooser’  
,:locals =\>{:response =\> @response}  
page.visual\_effect(:Appear, ‘fields\_chooser’)

I think this should fix it.
