Pass a ruby value to javascript in form_remote_tag

hi, guys, I am trying to pass a ruby value to a javascript function
which is called in “:complete” of a form_remote_tag, but everytime I
submit the form, javascript can’t get the changed value.

Here is how I tried.

in rhtml file,
<%= form_remote_tag :url =>{:action => ‘dosomething’},
:complete => “func(#{@session[:var]});”%>


<%= end_form_tag %>

in rb file,

class MyController < ApplicationController
def dosomething
# update var and put it into session

end
end

Any hints on what’s wrong here?

And I tried the way Pratik mentioned
here(http://www.ruby-forum.com/topic/73891#109323) to regenerate the
javascript,
but it seems not working.

Advices will be appreciated.

                :complete => "func(#{@session[:var]});"%>

it’s the quotes i think
try

                :complete => "func( '#{@session[:var]}' );"%>

hope this helps,
phil

On 6 Sep., 19:59, “Deramoo A.” [email protected]

thank you, phil, I tried that way, but it didn’t work. The value
remained to
be the same as html first rendered.

deramoo

[email protected] wrote:

                :complete => "func(#{@session[:var]});"%>

it’s the quotes i think
try

                :complete => "func( '#{@session[:var]}' );"%>

hope this helps,
phil

On 6 Sep., 19:59, “Deramoo A.” [email protected]

Now I put the value into XMLHttpRequest, and pass
the whole responseText of XMLHttpRequest to the javascript function.
Thus I can parse the text and get the updated ruby value.
It’s quite a lame solution, I think, but by now I have no other ways.

Deramoo A. wrote:

thank you, phil, I tried that way, but it didn’t work. The value
remained to
be the same as html first rendered.

deramoo

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs