Passing a ruby arrays to JS func

How do I pass the ruby arrays to Js func and access it(from JS func)from
a view page.. In my view page I have defined an array as

    <% asset.push({'url' => image['url'],
  'height' => height_ser,
  'width'=> width_ser
   }) %>

And I have passed this array as

    <%= submit_tag "
Continue",:Onclick=>"insert_slide(#{asset['height'].to_json},
#{asset['width'].to_json)" %>

But in the JS function(defined as function insert_slide(height, width))
of insert_slide I am not able to access this array of height and width

It is showing an error as asset_org is not defined... Any inputs on
this??

···

--
Posted via http://www.ruby-forum.com/.

ruby rails wrote in post #1010550:

How do I pass the ruby arrays to Js func and access it(from JS func)from
a view page.. In my view page I have defined an array as

It sounds to me like you're asking a question about writing applications
in Rails, not Ruby. If so, a Rails forum/mailing list would be the
appropriate place to ask.

But in the JS function(defined as function insert_slide(height, width))
of insert_slide I am not able to access this array of height and width

It is showing an error as asset_org is not defined... Any inputs on
this??

In none of the code you shown is there any "asset_org". So it sounds to
me like a bug in your javascript. I suggest you try using a javascript
console, and running insert_slide(100,50) and see what happens. If it
fails, you can post the details of the insert_slide function to a
javascript mailing list.

···

--
Posted via http://www.ruby-forum.com/\.

How do I pass the ruby arrays to Js func and access it(from JS func)from
a view page.. In my view page

Hold up... Ruby doesn't have "view pages" by itself. Maybe you wanted:

http://groups.google.com/group/rubyonrails-talk

I'll try to answer anyway, but you haven't given a lot of information here.

I have defined an array as

    <% asset.push({'url' => image['url'],
  'height' => height_ser,
  'width'=> width_ser
   }) %>

I don't think that defines an array, and I'm not sure it belongs in view code
anyway. But where is 'asset' actually defined?

And I have passed this array as

    <%= submit_tag "
Continue",:Onclick=>"insert_slide(#{asset['height'].to_json},
#{asset['width'].to_json)" %>

That's really not looking like an array. It's looking like you're accessing a
hash.

So now there's an even more important question: What is 'height_ser' and
'width_ser', and where are those defined? Do you really need to convert them
to json here?

But in the JS function(defined as function insert_slide(height, width))
of insert_slide I am not able to access this array of height and width

It is showing an error as asset_org is not defined... Any inputs on
this??

What's asset_org? You never mentioned it before this.

Wherever you end up asking your question, you probably want to provide a LOT
more detail. Paste the actual error, and if it's a stacktrace, you may want to
paste at least a few more lines of it than you think you need, if not the
entire trace.

···

On Wednesday, July 13, 2011 03:40:10 PM ruby rails wrote:

Somebody doesn't like Ruby/Javascript interactions... :smiley:

···

On Thu, Jul 14, 2011 at 06:38:46AM +0900, Doug Stone wrote:

unsubscribe

--
Darryl L. Pierce <mcpierce@gmail.com>
http://mcpierce.multiply.com/
"What do you care what people think, Mr. Feynman?"

Maybe because he saw [this](https://github.com/jessesielaff/red). :slight_smile: