Forum: Ruby on Rails passing data from controller to rjs and then to partial

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
612a5333e356c4f765230d9ac06e5c8c?d=identicon&s=25 Pradeep Sethi (psethi2000)
on 2006-05-02 06:41
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
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2006-05-02 07:39
Did you mean @response instead of "response"?

Pradeep Sethi wrote:
> Hello Experts,
>
> I am fetching data in my controller from a web service
>
> def search
>    response = @@api.DoSearch()
> end
>
<trim>
612a5333e356c4f765230d9ac06e5c8c?d=identicon&s=25 Pradeep Sethi (psethi2000)
on 2006-05-02 08:05
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 Ross wrote:
> Did you mean @response instead of "response"?
>
> Pradeep Sethi wrote:
>> Hello Experts,
>>
>> I am fetching data in my controller from a web service
>>
>> def search
>>    response = @@api.DoSearch()
>> end
>>
> <trim>
59ea1b450935b9d70abfec4186b7a4d5?d=identicon&s=25 Jeff Coleman (progressions)
on 2006-05-02 12:23
Pradeep Sethi 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
9d1f5d2d9de70bd9a934f557dc95a406?d=identicon&s=25 Daniel ----- (liquid)
on 2006-05-03 18:59
(Received via mailing list)
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.
This topic is locked and can not be replied to.