How To pass Ruby Object to JavaScript function

If you want to pass ruby object to javascript function then do the followin steps…

In Ruby Controller Action…
def sample
ruby_variable = “Something”
ruby_variable.to_json
end

In Ruby RJS File

page.call ‘java_script_function_name’, ruby_variable

In JavaScript
function java_script_function_name(java_script_variable){
alert(java_script_variable);
}

java_script_variable comes in the form of array of javascript.
Add comments if anyone wants

You can leave a response, or trackback from your own site.

Leave a Reply

You must be logged in to post a comment.